AWS CLI Cheat Sheet
Quick reference for AWS CLI commands. S3, EC2, Lambda, IAM, CloudFormation, ECS, and more — the most-used AWS commands in one page.
Configuration
S3 (Storage)
EC2 (Compute)
Lambda (Serverless)
IAM (Identity)
CloudFormation / CDK
ECS / ECR (Containers)
Useful Flags
Configuration
| aws configure | Set up credentials and default region |
| aws configure --profile prod | Configure named profile |
| aws sts get-caller-identity | Verify who you are (account, user, ARN) |
| export AWS_PROFILE=prod | Switch active profile |
| aws configure list | Show current configuration |
S3 (Storage)
| aws s3 ls | List all buckets |
| aws s3 ls s3://bucket/prefix/ | List objects in bucket |
| aws s3 cp file.txt s3://bucket/ | Upload file to S3 |
| aws s3 cp s3://bucket/file.txt . | Download file from S3 |
| aws s3 sync ./dir s3://bucket/dir | Sync local directory to S3 |
| aws s3 rm s3://bucket/file.txt | Delete object |
| aws s3 rm s3://bucket/ --recursive | Delete all objects in prefix |
| aws s3 mb s3://new-bucket | Create bucket |
| aws s3 presign s3://bucket/file --expires-in 3600 | Generate pre-signed URL (1 hour) |
EC2 (Compute)
| aws ec2 describe-instances | List all instances |
| aws ec2 start-instances --instance-ids i-xxx | Start instance |
| aws ec2 stop-instances --instance-ids i-xxx | Stop instance |
| aws ec2 terminate-instances --instance-ids i-xxx | Terminate instance |
| aws ec2 describe-security-groups | List security groups |
| aws ec2 describe-vpcs | List VPCs |
| aws ec2 create-key-pair --key-name my-key | Create SSH key pair |
| aws ec2 describe-images --owners amazon --filters "Name=name,Values=amzn2-ami-hvm-*" | Find Amazon Linux 2 AMI |
Lambda (Serverless)
| aws lambda list-functions | List all Lambda functions |
| aws lambda invoke --function-name myFunc out.json | Invoke function |
| aws lambda create-function --function-name myFunc --runtime nodejs20.x --handler index.handler --zip-file fileb://code.zip --role arn:aws:iam::xxx:role/xxx | Create function |
| aws lambda update-function-code --function-name myFunc --zip-file fileb://code.zip | Update function code |
| aws lambda get-function --function-name myFunc | Get function details |
| aws logs tail /aws/lambda/myFunc --follow | Tail Lambda logs in real-time |
IAM (Identity)
| aws iam list-users | List all IAM users |
| aws iam list-roles | List all IAM roles |
| aws iam create-user --user-name dev | Create user |
| aws iam attach-user-policy --user-name dev --policy-arn arn:aws:iam::aws:policy/ReadOnlyAccess | Attach policy to user |
| aws iam create-role --role-name myRole --assume-role-policy-document file://trust.json | Create role |
| aws iam list-attached-user-policies --user-name dev | List user policies |
CloudFormation / CDK
| aws cloudformation deploy --template-file tpl.yml --stack-name myStack | Deploy stack |
| aws cloudformation describe-stacks --stack-name myStack | Stack status |
| aws cloudformation delete-stack --stack-name myStack | Delete stack |
| aws cloudformation list-stacks --stack-status-filter CREATE_COMPLETE | List active stacks |
| aws cloudformation describe-stack-events --stack-name myStack | Stack events/logs |
ECS / ECR (Containers)
| aws ecr get-login-password | docker login --username AWS --password-stdin xxx.dkr.ecr.region.amazonaws.com | Docker login to ECR |
| aws ecr create-repository --repository-name myapp | Create ECR repository |
| aws ecs list-clusters | List ECS clusters |
| aws ecs list-services --cluster myCluster | List services in cluster |
| aws ecs update-service --cluster myCluster --service mySvc --force-new-deployment | Force redeploy |
| aws ecs describe-tasks --cluster myCluster --tasks arn:xxx | Task details |
Useful Flags
| --output json|table|text | Change output format |
| --query "Reservations[].Instances[].InstanceId" | JMESPath query to filter output |
| --region us-west-2 | Override region for this command |
| --profile prod | Use named profile |
| --no-paginate | Disable pagination (get all results) |
| --dry-run | Test command without executing (EC2) |
Step-by-Step Guide
Read Guide →