Skip to content
ohsudo, Home
Cloud

AWS CLI Cheat Sheet

The AWS CLI commands you use every day: profiles and SSO, who am I, filtering output with --query, S3 copy and sync, EC2 lookups, logs and Session Manager.

Updated November 15, 2026 · Applies to AWS CLI v2

Credentials and profiles

Terminal window
aws configure # access key, secret, region, output
aws configure --profile prod
aws configure sso # IAM Identity Center
aws sso login --profile prod
aws configure list # what's in use, and from where
aws configure list-profiles
export AWS_PROFILE=prod # for this shell
aws sts get-caller-identity # who am I, in which account

Order used: command options, environment variables, ~/.aws/credentials and ~/.aws/config, then the instance or container role.

Output and filters

Terminal window
aws ec2 describe-instances --output table
aws ec2 describe-instances --query 'Reservations[].Instances[].[InstanceId,State.Name]' --output text
aws ec2 describe-instances --filters 'Name=tag:Name,Values=web*' --query 'Reservations[].Instances[].PrivateIpAddress'
aws s3api list-buckets --query 'Buckets[].Name' --output text
aws ec2 describe-regions --query 'Regions[].RegionName' --output text

--filters filters on AWS’s side; --query (JMESPath) shapes the answer on yours.

S3

Terminal window
aws s3 ls # buckets
aws s3 ls s3://acme-logs/2026/ --recursive --human-readable --summarize
aws s3 cp backup.tar.gz s3://acme-backups/
aws s3 cp s3://acme-backups/backup.tar.gz .
aws s3 sync ./site s3://acme-site --delete --dryrun # preview, then drop --dryrun
aws s3 rm s3://acme-tmp/ --recursive
aws s3 presign s3://acme-backups/backup.tar.gz --expires-in 3600
aws s3 mb s3://acme-new-bucket

EC2

Terminal window
aws ec2 describe-instances --instance-ids i-0abc123
aws ec2 start-instances --instance-ids i-0abc123
aws ec2 stop-instances --instance-ids i-0abc123
aws ec2 describe-security-groups --group-ids sg-0abc123
aws ssm start-session --target i-0abc123 # shell without SSH (Session Manager plugin)

Logs and IAM

Terminal window
aws logs tail /aws/lambda/api --follow --since 10m
aws logs tail /ecs/web --filter-pattern ERROR
aws iam list-attached-role-policies --role-name app-role
aws iam simulate-principal-policy --policy-source-arn arn:aws:iam::123456789012:role/app-role \
--action-names s3:GetObject --resource-arns arn:aws:s3:::acme-logs/*

Handy options

Terminal window
--region eu-central-1 # override the region
--profile prod # override the profile
--no-cli-pager # don't open less
--debug # every request, signature and answer
--endpoint-url http://localhost:4566 # LocalStack or another S3 API

Common errors

Other cheat sheets