Skip to main content

Command Palette

Search for a command to run...

πŸš€ AWS CLI Deep Dive | Complete Beginner Guide (Concepts, Installation & Hands-on Demo)

Updated
β€’19 min readβ€’View as Markdown
πŸš€ AWS CLI Deep Dive | Complete Beginner Guide (Concepts, Installation & Hands-on Demo)
H
πŸ‘‹ Hi, I’m Hritik Ranjan β€” a B.Tech CSE student and a passionate tech enthusiast focused on Quality Engineering, AI/ML, Cybersecurity, and DevOps. πŸ’‘ I enjoy building and testing scalable, secure, and intelligent systems that solve real-world problems. My expertise and interests include: πŸ”Ή Quality Assurance & Testing Hands-on experience in manual and automation testing using Selenium & Java, ensuring high-quality and reliable applications. πŸ”Ή Artificial Intelligence & Machine Learning Exploring advanced algorithms and developing intelligent systems for practical use cases. πŸ”Ή Cybersecurity Focused on vulnerability assessment, security testing, and system hardening. πŸ”Ή Web Development Building responsive and user-friendly applications using modern technologies. πŸ”Ή Data Science Analyzing complex data to extract actionable insights. πŸ’Ό Key Projects: πŸš€ Blindness Detection System Applied computer vision techniques to detect blindness-related conditions. πŸš€ AI-Powered Rail Madad Enhancement Developed an intelligent complaint management system to improve railway customer service. πŸš€ Interactive Applications Built multiple projects like quiz apps, calculators, and productivity tools. 🌱 I’m continuously learning and improving my skills in DevOps, Cloud, and Automation to become a well-rounded engineer. 🀝 Open to collaborations, internships, and opportunities in QA, DevOps, AI/ML, and Cybersecurity. πŸ“« Let’s connect: hritikranjan1408@gmail.com

The AWS Command Line Interface (AWS CLI) is one of the most important tools for DevOps Engineers, Cloud Engineers, and System Administrators. While the AWS Management Console (GUI) is excellent for beginners, manually clicking through the console becomes slow and inefficient as your infrastructure grows.

AWS CLI enables you to manage AWS services directly from the terminal, automate repetitive tasks, integrate with CI/CD pipelines, and interact with AWS services through simple commands.

In this guide, we'll cover everything a beginner needs to know about AWS CLI, including installation, configuration, authentication, practical commands, best practices, common errors, interview questions, and real-world DevOps use cases.


πŸ“š Table of Contents

  • What is AWS CLI?

  • Why Do We Need AWS CLI?

  • AWS Console vs AWS CLI

  • How AWS CLI Works

  • AWS CLI Architecture

  • AWS CLI Components

  • AWS CLI Versions

  • Prerequisites

  • Installing AWS CLI

  • Configuring AWS CLI

  • AWS Credentials Explained

  • Understanding IAM Access Keys

  • AWS CLI Profiles

  • Important AWS CLI Commands

  • Working with S3

  • Working with EC2

  • Working with IAM

  • Working with VPC

  • Output Formats

  • Regions & Availability Zones

  • AWS CLI Best Practices

  • Common Errors

  • DevOps Use Cases

  • Advantages & Limitations

  • Interview Questions

  • Summary


☁️ What is AWS CLI?

AWS CLI (Amazon Web Services Command Line Interface) is an official command-line tool provided by AWS that allows you to interact with AWS services using terminal commands instead of the AWS Management Console.

Instead of opening your browser and clicking through multiple pages, you can create, update, delete, and manage AWS resources using simple commands.

For example:

aws s3 ls

This command lists all S3 buckets in your AWS account.


πŸ€” Why Do We Need AWS CLI?

Imagine you need to create:

  • 50 EC2 instances

  • 100 S3 buckets

  • Multiple IAM users

  • Several VPCs

Doing this manually through the AWS Console would take a lot of time.

AWS CLI makes these tasks much faster and allows you to automate them.

Benefits

  • Faster than GUI

  • Automation friendly

  • Easy scripting

  • CI/CD integration

  • Infrastructure management

  • Remote management

  • Repeatable operations


πŸ–₯ AWS Console vs AWS CLI

AWS Console AWS CLI
Graphical Interface Command Line Interface
Beginner Friendly Automation Friendly
Manual Operations Scripted Operations
Slow for Repetitive Tasks Very Fast
Good for Learning Best for Production

βš™οΈ How AWS CLI Works

The workflow is simple:

User

↓

AWS CLI Command

↓

AWS CLI Tool

↓

AWS API

↓

AWS Service

↓

Response

Example:

aws s3 ls

↓

AWS CLI

↓

S3 API

↓

Amazon S3

↓

Bucket List

The AWS CLI acts as a bridge between your terminal and AWS services.


πŸ— AWS CLI Architecture

Developer

↓

Terminal

↓

AWS CLI

↓

Authentication (IAM)

↓

AWS APIs

↓

AWS Services

β€’ EC2
β€’ S3
β€’ IAM
β€’ Lambda
β€’ RDS
β€’ CloudWatch
β€’ VPC

πŸ”₯ Why DevOps Engineers Use AWS CLI

AWS CLI is widely used for:

  • Infrastructure Automation

  • CI/CD Pipelines

  • Deployment Scripts

  • Backup Automation

  • Monitoring

  • Resource Management

  • Security Audits

  • Troubleshooting


πŸ“¦ AWS CLI Versions

There are two versions available:

Version 1

Older version with fewer features.


Latest version with:

  • Better security

  • SSO support

  • Auto prompt

  • Improved performance

  • More AWS services

Always install Version 2.


βœ… Prerequisites

Before installing AWS CLI, ensure you have:

  • An AWS Account

  • An IAM User (avoid using the Root user)

  • Access Key ID

  • Secret Access Key

  • Internet connection


πŸ’» Installing AWS CLI

Windows

  1. Visit the official AWS CLI download page.

  2. Download the MSI installer.

  3. Run the installer.

  4. Complete the installation wizard.

  5. Verify the installation:

aws --version

Ubuntu / Linux

Update packages:

sudo apt update

Install AWS CLI:

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"

Extract:

unzip awscliv2.zip

Install:

sudo ./aws/install

Verify:

aws --version

macOS

Using Homebrew:

brew install awscli

Verify:

aws --version

πŸ” Configuring AWS CLI

After installation, configure AWS CLI using:

aws configure

You'll be prompted for:

AWS Access Key ID

AWS Secret Access Key

Default Region

Output Format

Example:

Access Key:
AKIA....

Secret Key:
****************

Region:
ap-south-1

Output:
json

πŸ”‘ What are Access Keys?

Access Keys are credentials that allow AWS CLI to authenticate with your AWS account.

They consist of:

  • Access Key ID

  • Secret Access Key

These should be created for an IAM user with the minimum required permissions.

⚠️ Never use the Root Account's access keys for daily work.


πŸ“‚ AWS CLI Configuration Files

AWS CLI stores configuration in:

Credentials:

~/.aws/credentials

Example:

[default]
aws_access_key_id = AKIA...
aws_secret_access_key = ********

Configuration:

~/.aws/config

Example:

[default]
region=ap-south-1
output=json

πŸ‘€ AWS CLI Profiles

You can manage multiple AWS accounts using profiles.

Create a profile:

aws configure --profile dev

Use it:

aws s3 ls --profile dev

This is useful for managing Dev, Test, and Production environments.


πŸ“Š Common AWS CLI Commands

Check Version

aws --version

View Current Configuration

aws configure list

List All S3 Buckets

aws s3 ls

List EC2 Instances

aws ec2 describe-instances

List IAM Users

aws iam list-users

List VPCs

aws ec2 describe-vpcs

☁️ Working with Amazon S3

Create Bucket

aws s3 mb s3://my-demo-bucket

Upload File

aws s3 cp image.png s3://my-demo-bucket

Download File

aws s3 cp s3://my-demo-bucket/image.png .

Delete File

aws s3 rm s3://my-demo-bucket/image.png

Delete Bucket

aws s3 rb s3://my-demo-bucket

πŸ–₯ Working with EC2

List Instances

aws ec2 describe-instances

Start Instance

aws ec2 start-instances --instance-ids i-123456

Stop Instance

aws ec2 stop-instances --instance-ids i-123456

Reboot Instance

aws ec2 reboot-instances --instance-ids i-123456

Terminate Instance

aws ec2 terminate-instances --instance-ids i-123456

πŸ‘€ Working with IAM

List Users

aws iam list-users

List Roles

aws iam list-roles

List Policies

aws iam list-policies

🌐 Working with VPC

List VPCs

aws ec2 describe-vpcs

List Subnets

aws ec2 describe-subnets

List Security Groups

aws ec2 describe-security-groups

πŸ“€ Output Formats

AWS CLI supports:

  • JSON (default)

  • YAML

  • Text

  • Table

Example:

aws s3 ls --output table

🌍 Regions

Specify a region:

aws s3 ls --region ap-south-1

Examples:

  • ap-south-1 (Mumbai)

  • us-east-1 (N. Virginia)

  • eu-west-1 (Ireland)


⚑ Common Errors

Invalid Credentials

Cause: Wrong Access Key or Secret Key.

Solution:

aws configure

Re-enter credentials.


Access Denied

Cause: IAM user lacks permissions.

Solution: Attach the required IAM policy.


Region Not Found

Cause: Invalid region name.

Solution:

aws configure

Set the correct region.


Command Not Found

Cause: AWS CLI is not installed or not added to the system PATH.


πŸš€ DevOps Use Cases

AWS CLI is commonly used for:

  • Creating infrastructure

  • Automating backups

  • CI/CD pipelines

  • Deploying applications

  • Creating S3 buckets

  • Launching EC2 instances

  • Managing IAM users

  • Monitoring CloudWatch

  • Infrastructure automation scripts

  • Terraform integration

  • Jenkins pipelines

  • GitHub Actions workflows


⭐ Best Practices

  • Never use the Root account.

  • Use IAM users or IAM roles.

  • Follow the Principle of Least Privilege.

  • Rotate Access Keys regularly.

  • Use profiles for multiple accounts.

  • Avoid hardcoding credentials.

  • Store secrets securely using AWS Secrets Manager or Parameter Store.

  • Enable MFA for IAM users.

  • Keep AWS CLI updated.


🎯 Advantages

  • Easy to automate

  • Faster than the AWS Console

  • Supports all AWS services

  • Script-friendly

  • Works with CI/CD tools

  • Free to use

  • Cross-platform


⚠️ Limitations

  • Requires command-line knowledge

  • Typing errors can cause failures

  • Less visual than the AWS Console

  • Requires secure credential management


πŸ“Œ Real-World Example

A DevOps engineer needs to upload build artifacts after a successful Jenkins pipeline.

Instead of uploading them manually through the AWS Console, the pipeline runs:

aws s3 cp build.zip s3://company-artifacts/

This automates the deployment process, reduces manual effort, and ensures consistency across environments.


AWS CLI Interview Questions & Answers (Beginner to Advanced) πŸš€

These are some of the most frequently asked AWS CLI interview questions for DevOps Engineers, Cloud Engineers, AWS Administrators, SREs, and Solutions Architects.


Q1. What is AWS CLI?

Answer:

AWS CLI (Amazon Web Services Command Line Interface) is a command-line tool that allows users to manage AWS services directly from the terminal instead of using the AWS Management Console.

It communicates with AWS services through AWS APIs and helps automate cloud infrastructure.

Example

aws s3 ls

Lists all S3 buckets in your AWS account.


Q2. Why do DevOps Engineers prefer AWS CLI over AWS Console?

Answer

AWS Console is suitable for beginners and small tasks, but it is not practical for automation.

AWS CLI is preferred because it:

  • Automates repetitive tasks

  • Works inside Shell Scripts

  • Can be integrated with CI/CD

  • Saves time

  • Eliminates manual work

  • Reduces human errors

For example, instead of creating 100 EC2 instances manually, one AWS CLI command can launch them all.


Q3. How does AWS CLI work?

Answer

AWS CLI works in the following flow:

User Command
      β”‚
      β–Ό
AWS CLI
      β”‚
      β–Ό
AWS API
      β”‚
      β–Ό
AWS Service

Example

aws ec2 describe-instances

AWS CLI sends the request to EC2 APIs, which return the response to the terminal.


Q4. What are the prerequisites before using AWS CLI?

Answer

You need:

  • AWS Account

  • IAM User

  • Access Key ID

  • Secret Access Key

  • AWS CLI Installed

  • Internet Connection

Never use the Root User for daily tasks.


Q5. How do you install AWS CLI?

Answer

Linux

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o awscliv2.zip

unzip awscliv2.zip

sudo ./aws/install

Windows

Download the AWS CLI installer from AWS Official Website and install it.

MacOS

brew install awscli

Verify Installation

aws --version

Example

aws-cli/2.17.0 Python/3.x

Q6. How do you configure AWS CLI?

Answer

Run

aws configure

It asks for

AWS Access Key ID

AWS Secret Access Key

Default Region

Output Format

Example

AWS Access Key ID: AKIA***********

AWS Secret Access Key: ************

Region: ap-south-1

Output: json

Q7. Where does AWS CLI store credentials?

Answer

Linux/Mac

~/.aws/credentials

~/.aws/config

Windows

C:\Users\<Username>\.aws\

These files store:

  • Access Keys

  • Region

  • Output Format

  • Profiles


Q8. What are Access Keys?

Answer

Access Keys are credentials used by AWS CLI or applications to authenticate with AWS.

They contain:

  • Access Key ID

  • Secret Access Key

These are generated from IAM Users.


Q9. Why should we use IAM Users instead of the Root User?

Answer

Using the Root User is dangerous because it has unrestricted permissions.

Best Practice:

  • Create IAM Users

  • Attach only required permissions

  • Enable MFA

  • Disable Root User usage

This follows the Principle of Least Privilege.


Q10. How do you check whether AWS CLI is configured correctly?

Answer

Run

aws sts get-caller-identity

Example Output

{
  "UserId": "...",
  "Account": "...",
  "Arn": "arn:aws:iam::123456789:user/devops"
}

If details are returned, AWS CLI is configured correctly.


Q11. How do you list all S3 Buckets?

Answer

aws s3 ls

Example

company-backup

project-files

logs-bucket

Q12. How do you create an S3 Bucket using AWS CLI?

Answer

aws s3 mb s3://my-demo-bucket

Q13. How do you upload a file to S3?

Answer

aws s3 cp demo.txt s3://my-demo-bucket

Q14. How do you download a file from S3?

Answer

aws s3 cp s3://my-demo-bucket/demo.txt .

Q15. How do you synchronize folders with S3?

Answer

aws s3 sync ./website s3://mybucket

This uploads only changed files.


Q16. How do you list EC2 Instances?

Answer

aws ec2 describe-instances

Q17. How do you launch an EC2 Instance using AWS CLI?

Answer

Example

aws ec2 run-instances \
--image-id ami-xxxxxxxx \
--instance-type t2.micro \
--key-name MyKey \
--security-group-ids sg-xxxx \
--subnet-id subnet-xxxx

This launches a new EC2 instance.


Q18. How do you stop an EC2 Instance?

Answer

aws ec2 stop-instances \
--instance-ids i-1234567890

Q19. How do you start an EC2 Instance?

Answer

aws ec2 start-instances \
--instance-ids i-1234567890

Q20. How do you terminate an EC2 Instance?

Answer

aws ec2 terminate-instances \
--instance-ids i-1234567890

Q21. What is the difference between AWS CLI and AWS SDK?

Answer

AWS CLI AWS SDK
Command-line tool Programming library
Used manually Used inside applications
Shell automation Code automation
No coding required Requires programming language

Q22. AWS CLI vs Terraform

Answer

AWS CLI Terraform
Individual commands Infrastructure as Code
Good for quick tasks Good for complete infrastructure
Imperative Declarative
Manual automation Full infrastructure management

Q23. AWS CLI vs CloudFormation

Answer

AWS CLI

  • Executes one command at a time

  • Better for quick operations

CloudFormation

  • Creates entire infrastructure using templates

  • Suitable for production deployments


Q24. What output formats does AWS CLI support?

Answer

Supported formats:

json

text

table

yaml

Example

aws ec2 describe-instances --output table

Q25. How do you change the default AWS Region?

Answer

Run

aws configure

or

aws configure set region ap-south-1

Q26. What are AWS CLI Profiles?

Answer

Profiles allow you to manage multiple AWS accounts on the same machine.

Example

aws configure --profile production

aws configure --profile testing

Use

aws s3 ls --profile production

Q27. How do you view all configured AWS Profiles?

Answer

aws configure list-profiles

Q28. How do you debug AWS CLI commands?

Answer

Use

aws s3 ls --debug

This shows:

  • API Requests

  • Authentication

  • Headers

  • Errors

  • Responses

Useful for troubleshooting.


Q29. How do you get help for AWS CLI commands?

Answer

General help

aws help

Service help

aws ec2 help

Specific command

aws ec2 run-instances help

Q30. What are the best practices for AWS CLI?

Answer

  • Never use the Root User.

  • Use IAM Users or IAM Roles.

  • Follow the Principle of Least Privilege.

  • Rotate Access Keys regularly.

  • Enable Multi-Factor Authentication (MFA).

  • Use named profiles for multiple AWS accounts.

  • Never hardcode Access Keys in scripts.

  • Store secrets securely using AWS Secrets Manager or environment variables.

  • Prefer IAM Roles for EC2, Lambda, and ECS instead of long-term access keys.

  • Keep AWS CLI updated to the latest version.

  • Use automation (Shell Scripts, CI/CD pipelines) instead of manual commands whenever possible.


⭐ Quick Interview Tips

If an interviewer asks "Why AWS CLI when we already have the AWS Console?", you can answer:

"The AWS Console is ideal for learning and occasional manual tasks, but it doesn't scale well for repetitive operations. AWS CLI enables automation through scripts, integrates seamlessly with CI/CD pipelines like Jenkins and GitHub Actions, and allows infrastructure to be managed quickly, consistently, and with fewer human errors. That's why DevOps engineers rely on AWS CLI for day-to-day cloud automation."


πŸš€ Continue Your Learning Journey

Thank you for taking the time to read this article.

Technology is evolving rapidly, and continuous learning is one of the most valuable investments you can make in your career. Whether you're exploring DevOps, Cloud Computing, Artificial Intelligence, Cybersecurity, Software Development, Data Science, or Career Growth, the resources below can help you deepen your knowledge and stay ahead in the industry.


πŸŽ“ Recommended Learning Platforms

πŸš€ Coursera

Learn from world-renowned universities and industry leaders including Google, IBM, Stanford, Microsoft, Meta, and many more.

βœ” Professional Certificates βœ” Career-focused Learning Paths βœ” AI & Machine Learning Programs βœ” Cloud & DevOps Certifications βœ” Business & Leadership Courses

πŸ”— https://imp.i384100.net/k0KvbV


πŸ’» Udemy

One of the largest online learning platforms with practical, hands-on courses covering:

βœ” DevOps & Kubernetes βœ” Docker & Cloud Computing βœ” AWS, Azure & GCP βœ” Programming & Development βœ” Cybersecurity & Ethical Hacking

πŸ”— https://trk.udemy.com/MAL2MY


πŸ“Š DataCamp

A great platform for anyone interested in:

βœ” Python Programming βœ” SQL & Databases βœ” Data Analytics βœ” Machine Learning βœ” Artificial Intelligence

Interactive learning paths and hands-on projects make it ideal for beginners and professionals alike.

πŸ”— https://datacamp.pxf.io/nX4kER


πŸŽ“ edX

Access high-quality courses and certifications from leading institutions such as:

βœ” Harvard University βœ” MIT βœ” Berkeley βœ” Microsoft

Perfect for learners seeking university-level education online.

πŸ”— https://edx.sjv.io/POvVeN


🎨 Domestika

Enhance your creative skills with courses on:

βœ” Graphic Design βœ” Video Editing βœ” Animation βœ” Digital Marketing βœ” Content Creation

πŸ”— https://domestika.sjv.io/dynKAW


πŸ› οΈ Recommended Tools & Resources

πŸ”₯ AppSumo

Discover exclusive lifetime deals on:

βœ” AI Tools βœ” Productivity Software βœ” Developer Utilities βœ” Marketing Platforms βœ” Business Applications

A must-have resource for developers, creators, freelancers, and entrepreneurs looking to save money while accessing premium tools.

πŸ”— https://appsumo.8odi.net/L04a33


πŸ›’ Shopify

Looking to start an online business or launch an eCommerce store?

Shopify provides everything you need to build, manage, and scale an online business.

βœ” Online Store Builder βœ” Payment Integration βœ” Inventory Management βœ” Marketing Tools

πŸ”— https://shopify.pxf.io/Vxv09k


🌐 WordPress, WooCommerce & Jetpack

Create professional websites, blogs, and online stores with one of the most trusted web ecosystems in the world.

Ideal for:

βœ” Personal Blogs βœ” Portfolio Websites βœ” Business Websites βœ” eCommerce Stores

πŸ”— https://automattic.pxf.io/Z6vR5W


🌍 Language Learning Resources

πŸ—£οΈ Preply

Learn English and other languages through personalized one-on-one tutoring sessions with experts from around the world.

πŸ”— https://preply.sjv.io/o4gBDY


πŸ“š British Council English Online

Improve your professional communication skills and English fluency through structured learning programs.

πŸ”— https://englishonline.sjv.io/9VOGa4


🧠 Rosetta Stone

One of the most recognized language-learning platforms for immersive language acquisition.

πŸ”— https://aff.rosettastone.com/X4OyqG


πŸ§ͺ Science & Educational Resources

πŸ”¬ MEL Science

Interactive science kits and educational experiences designed to make STEM learning engaging and practical.

πŸ”— https://imp.i328067.net/bk2beg


πŸ“– Carson Dellosa Education

Educational materials and learning resources for students, teachers, and lifelong learners.

πŸ”— https://carsondellosaeducation.sjv.io/E0JbjW


❀️ Support My Work

Creating detailed technical content, tutorials, guides, and learning resources takes significant time and effort.

If you find my articles helpful and would like to support my work, you can do so through the following platforms:

⭐ Become a GitHub Sponsor

Support my open-source contributions, technical content, and community projects.

πŸ”— https://github.com/sponsors/hritikranjan1


β˜• Buy Me a Chai

Enjoying my content? Consider buying me a chai and supporting future tutorials, guides, and educational resources.

πŸ”— https://www.chai4.me/hritikranjan


πŸ‘¨β€πŸ’» Connect With Me

Hritik Ranjan

πŸ’‘ AI Enthusiast ☁️ DevOps Learner πŸ” Cybersecurity Advocate πŸ’» Software Developer

Connect & Follow

πŸ”— GitHub: https://github.com/hritikranjan1

πŸ”— LinkedIn: https://linkedin.com/in/hritikranjan1


πŸ“’ Found This Article Helpful?

If this article added value to your learning journey:

βœ… Share it with your network βœ… Bookmark it for future reference βœ… Follow for more DevOps, AI, Cloud, Cybersecurity, and Software Engineering content

Thank you for reading and being part of this learning journey.

Keep Learning. Keep Building. Keep Growing. πŸš€

AWS for DevOps β˜οΈπŸš€

Part 7 of 7

Learn AWS from a DevOps Engineer's perspective. This series covers AWS fundamentals, IAM, EC2, VPC, S3, Route 53, Load Balancers, Auto Scaling, CloudWatch, ECS, EKS, CI/CD, Infrastructure as Code, Monitoring, Security, and real-world DevOps projects using AWS.

Start from the beginning

☁️ DevOps with AWS – Zero to Hero Journey Begins | Course Overview πŸš€

Master AWS Cloud Fundamentals, DevOps Practices, Infrastructure Automation, CI/CD Pipelines, Kubernetes & Production-Level Cloud Architecture Step-by-Step