AWS CLI Command Library
Complete AWS CLI developer reference: installation, configuration, 600+ copy-paste commands for 225 services, output formatting patterns, JMESPath filtering, and production best practices. Bookmark this page — you will use it daily.
Install & Setup
brew install awsclicurl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"unzip awscliv2.zip && sudo ./aws/installmsiexec.exe /i https://awscli.amazonaws.com/AWSCLIV2.msidocker run --rm -it -v ~/.aws:/root/.aws amazon/aws-cli s3 lsaws --versionConfiguration
aws configurePrompts for: AWS Access Key ID, Secret Access Key, default region (e.g., us-east-1), default output format (json)
Common CLI Patterns
aws ec2 describe-instances --output tableHuman-readable table format for terminal — best for quick inspection
aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,InstanceType,State.Name,Tags[?Key==`Name`].Value|[0]]' --output tableExtract only instance ID, type, state, and Name tag — 90% smaller response
aws ec2 describe-instances --filters 'Name=tag:Environment,Values=production' --query 'Reservations[*].Instances[*].{ID:InstanceId,Type:InstanceType,State:State.Name}' --output tableFind all production instances by tag:Environment=production
aws s3api list-objects-v2 --bucket my-bucket --max-items 100 --starting-token eyJNYXJrZXI...Use --max-items with --starting-token from NextToken — prevents pulling millions of objects at once
aws ec2 wait instance-running --instance-ids i-1234567890abcdef0 && echo "Ready"Block until instance reaches running state — no polling loops needed
aws ec2 run-instances --image-id ami-0abcdef1234567890 --instance-type t3.micro --key-name my-key --dry-runValidate IAM permissions and parameters without creating resources — essential before automation
aws sts get-caller-identity --profile productionVerify which account/role a profile resolves to — always confirm before running commands in production
aws ec2 describe-instances --region eu-west-1 --profile stagingCombine --region and --profile for multi-account, multi-region operations
aws ec2 describe-instances --filters 'Name=instance-state-name,Values=running' --query 'Reservations[*].Instances[*].InstanceId' --output text | wc -wCount running instances across all regions — pipe CLI output to standard Unix tools
aws ec2 run-instances --generate-cli-skeleton | tee template.jsonGenerate JSON template for any command — edit and pass back with --cli-input-json file://template.json
CLI Best Practices
- 1Never hardcode AWS credentials — use IAM roles (EC2/Lambda/ECS), aws configure, or environment variables
- 2Use --dry-run before destructive commands (ec2 terminate-instances, rds delete-db-instance)
- 3Set --output to control format: json for automation, table for humans, text for shell pipelines
- 4Master --query (JMESPath) — it reduces response size by 90%+ and eliminates post-processing code
- 5Use --profile to separate production, staging, and dev environments — never mix credentials
- 6Enable command completion: complete -C aws_completer aws — saves keystrokes and prevents typos
- 7Set AWS CLI pagination defaults in ~/.aws/config: cli_pager=less, max_items=100
- 8Use AWS CloudShell for quick commands — pre-authenticated, no credential setup needed
- 9Prefer aws s3api over aws s3 for scripting — consistent JSON output, no human-friendly formatting surprises
- 10Pipe through jq for complex transformations: aws ec2 describe-instances | jq '.Reservations[].Instances[] | {id: .InstanceId, type: .InstanceType}'
Command Library — 225 Services
Analytics
(24)Compute
(19)Database
(15)Developer Tools
(15)End User Computing
(7)Integration
(17)IoT
(10)Machine Learning
(26)Management
(34)Migration
(4)Network
(17)Security
(25)Storage
(12)AWS CLI FAQ
How do I install AWS CLI v2?▼
macOS: brew install awscli. Linux: curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o awscliv2.zip && unzip awscliv2.zip && sudo ./aws/install. Windows: download MSI installer from AWS. Verify: aws --version.
How do I configure multiple AWS accounts?▼
Use named profiles: aws configure --profile production, aws configure --profile staging. Then run commands with --profile production or set AWS_PROFILE=production. Each profile stores separate credentials in ~/.aws/credentials.
How do I assume an IAM role from CLI?▼
Add the role to ~/.aws/config: [profile admin] role_arn=arn:aws:iam::123456789012:role/AdminRole source_profile=default. Then aws s3 ls --profile admin. The CLI automatically calls STS AssumeRole and caches temporary credentials.
How do I debug AWS CLI errors?▼
Add --debug to any command for full request/response dumps including HTTP headers, signed URLs, and timing. For less verbose: --no-verify-ssl (testing only). Check CloudTrail for API call history.
What is the difference between aws s3 and aws s3api?▼
aws s3 is a high-level shorthand (cp, sync, ls) with human-friendly output. aws s3api is the low-level API (list-objects, get-object) with consistent JSON output — better for scripting and automation.
How do I generate CLI skeleton input?▼
Use --generate-cli-skeleton to output a JSON template: aws ec2 run-instances --generate-cli-skeleton > template.json. Edit the JSON, then: aws ec2 run-instances --cli-input-json file://template.json.