Aws Cli
What is AWS CLI?
AWS CLI is a tool that allows you to manage AWS services using commands from your terminal or command prompt.
Instead of opening the AWS Console in a browser, you can:
Create EC2 instances
List S3 buckets
Upload files to S3
Check IAM users
Manage almost all AWS services
All from one place using commands.
In short:
AWS CLI = Control AWS using terminal commands
Why Should We Use AWS CLI?
Here are some simple reasons:
Faster than AWS Console
Easy to automate tasks
Very useful in DevOps
Can be used in scripts and CI/CD pipelines
Same commands work everywhere
If you want to move into DevOps or Cloud roles, AWS CLI is mandatory.
Prerequisites
Before using AWS CLI, you need:
An AWS account
IAM user with programmatic access
Access Key ID
Secret Access Key
You should never use the root account for CLI access.
Installing AWS CLI
On Linux (Ubuntu)
sudo apt update
sudo apt install awscli -y
Check version:
aws --version
On Windows
Download AWS CLI MSI installer from AWS official site
Install it like a normal software
Open Command Prompt and check:
aws --version
Configuring AWS CLI
After installation, you must configure AWS CLI.
Run:
aws configure
It will ask:
AWS Access Key ID: xxxxxxxxx
AWS Secret Access Key: xxxxxxxxx
Default region name: ap-south-1
Default output format: json
Now your AWS CLI is connected to your AWS account.
AWS CLI Configuration Files
AWS CLI stores configuration in two files:
~/.aws/credentials
~/.aws/config
You can check them using:
cat ~/.aws/credentials
cat ~/.aws/config
Basic AWS CLI Commands
Check AWS Identity
aws sts get-caller-identity
This command confirms:
Which account you are using
Which IAM user is configured
AWS S3 Commands
List all S3 Buckets
aws s3 lsCreate an S3 Bucket
aws s3 mb s3://my-first-cli-bucket
Upload File to S3
aws s3 cp file.txt s3://my-first-cli-bucket/Download File from S3
aws s3 cp s3://my-first-cli-bucket/file.txt .
Delete File from S3
aws s3 rm s3://my-first-cli-bucket/file.txtDelete S3 Bucket
aws s3 rb s3://my-first-cli-bucket --forceAWS EC2 Commands
List EC2 Instances
aws ec2 describe-instancesThis command gives full details of all instances in JSON format.
List Only Instance IDs
aws ec2 describe-instances \ --query "Reservations[].Instances[].InstanceId"
Start EC2 Instance
aws ec2 start-instances --instance-ids i-1234567890abcdef0
Stop EC2 Instance
aws ec2 stop-instances --instance-ids i-1234567890abcdef0
Terminate EC2 Instance
aws ec2 terminate-instances --instance-ids i-1234567890abcdef0Be careful. This action is permanent.
AWS IAM Commands
List IAM Users
aws iam list-users
List IAM Roles
aws iam list-roles
Get IAM User Details
aws iam get-user
Working With AWS Regions
List All Regions
aws ec2 describe-regions
Run Command in Specific Region
aws ec2 describe-instances --region us-east-1
Output Formats in AWS CLI
AWS CLI supports:
json
table
text
Example:
aws ec2 describe-instances --output table
Table output is easier to read.
AWS CLI Help Command
Whenever you are stuck, use:
aws help
Or for a specific service:
aws s3 help
This is very useful for beginners.
Common AWS CLI Errors
Access Denied
Reason:
- IAM user does not have required permissions
Solution:
- Attach correct IAM policy
Invalid Client Token
Reason:
- Wrong Access Key or Secret Key
Solution:
- Reconfigure AWS CLI
Best Practices for AWS CLI
Never expose Access Key in public
Use IAM roles where possible
Always follow least privilege principle
Stop unused resources to avoid billing
Practice commands in free tier
Conclusion
AWS CLI is a powerful tool that makes AWS easy and fast to use.
At first, commands may look difficult, but with practice, it becomes natural.
If you are learning AWS or planning to move into DevOps, start using AWS CLI daily.
It will improve your confidence and real-world skills.3