AWS CLI Cheat Sheet Installation & Configuration bash
Install AWS CLI (Linux/macOS)
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip sudo ./aws/install
Configure AWS CLI
aws configure
Then enter your AWS Access Key ID, Secret
Access Key, region (e.g., us-east-1), and
output format (e.g., json)
List current configuration
aws configure list Basic Commands bash
Get caller identity (check if
authenticated)
aws sts get-caller-identity
List all available AWS services
aws help | grep -A5 AVAILABLE
Get help for a specific service
aws ec2 help aws s3 help EC2 Commands bash
List all EC2 instances
aws ec2 describe-instances
Start/stop/terminate an instance
aws ec2 start-instances --instance-ids i-1234567890abcdef0 aws ec2 stop-instances --
instance-ids i-1234567890abcdef0 aws ec2 terminate-instances --instance-ids i-
1234567890abcdef0
List all AMIs you have access to
aws ec2 describe-images --owners self
Create a new key pair
aws ec2 create-key-pair --key-name MyKeyPair --query 'KeyMaterial' --output text >
MyKeyPair.pem S3 Commands bash
List all buckets
aws s3 ls
Create a bucket
aws s3 mb s3://bucket-name
Delete a bucket
aws s3 rb s3://bucket-name --force
Sync local directory to S3
aws s3 sync ./local-folder s3://bucket-name/remote-folder
Copy file to S3
aws s3 cp file.txt s3://bucket-name/path/to/file.txt
Download file from S3
aws s3 cp s3://bucket-name/path/to/file.txt ./local-file.txt IAM Commands bash
List all IAM users
aws iam list-users
Create a new IAM user
aws iam create-user --user-name new-user
Create access key for user
aws iam create-access-key --user-name new-user
List all policies
aws iam list-policies
Attach policy to user
aws iam attach-user-policy --user-name new-user --policy-arn
arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess Lambda Commands bash
List all Lambda functions
aws lambda list-functions
Invoke a Lambda function
aws lambda invoke --function-name my-function --payload '{"key":"value"}' output.txt
Create a new Lambda function
aws lambda create-function --function-name my-function
--runtime python3.8 --handler lambda_function.lambda_handler
--role arn:aws:iam::123456789012:role/lambda-role
--zip-file fileb://function.zip CloudWatch Commands bash
List all CloudWatch alarms
aws cloudwatch describe-alarms
Get CloudWatch metrics
aws cloudwatch list-metrics --namespace AWS/EC2
Get metric statistics
aws cloudwatch get-metric-statistics --namespace AWS/EC2
--metric-name CPUUtilization --dimensions Name=InstanceId,Value=i-1234567890abcdef0
--start-time 2023-01-01T00:00:00Z --end-time 2023-01-02T00:00:00Z
--period 3600 --statistics Average Maximum Minimum RDS Commands bash
List all RDS instances
aws rds describe-db-instances
Create a database snapshot
aws rds create-db-snapshot --db-instance-identifier mydb --db-snapshot-identifier
mydb-snapshot
Restore database from snapshot
aws rds restore-db-instance-from-db-snapshot
--db-instance-identifier mydb-restored
--db-snapshot-identifier mydb-snapshot Common Options bash
Output format (json, text, table, yaml)
aws ec2 describe-instances --output json aws ec2 describe-instances --output table aws
ec2 describe-instances --output text aws ec2 describe-instances --output yaml
Query filtering (JMESPath)
aws ec2 describe-instances --query 'Reservations[].Instances[].
{Instance:InstanceId,State:State.Name}'
Filter results
aws ec2 describe-instances --filters "Name=instance-type,Values=t2.micro"
Region selection
aws ec2 describe-instances --region us-west-2
Profile selection (for multiple AWS
accounts)
aws ec2 describe-instances --profile dev-profile Tips Use --query to filter and format
output
Use --dry-run to test commands without making changes
Use --debug for troubleshooting
Use --no-cli-pager to prevent output from opening in a pager
Use --page-size and --max-items for pagination control