Developer Reference

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

macOS
brew install awscli
Linux (x86_64)
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"unzip awscliv2.zip && sudo ./aws/install
Windows
msiexec.exe /i https://awscli.amazonaws.com/AWSCLIV2.msi
Docker
docker run --rm -it -v ~/.aws:/root/.aws amazon/aws-cli s3 ls
Verify installation
aws --version

Configuration

Quick setup (single account)
aws configure

Prompts for: AWS Access Key ID, Secret Access Key, default region (e.g., us-east-1), default output format (json)

Multiple profiles (~/.aws/credentials)
[default]
aws_access_key_id = AKIA...
aws_secret_access_key = ...
[production]
aws_access_key_id = AKIA...
aws_secret_access_key = ...
region = eu-west-1
[staging]
role_arn = arn:aws:iam::123456789012:role/AdminRole
source_profile = default
Use: aws s3 ls --profile production

Common CLI Patterns

Output as Table (human-readable)
aws ec2 describe-instances --output table

Human-readable table format for terminal — best for quick inspection

Filter with JMESPath (extract fields)
aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,InstanceType,State.Name,Tags[?Key==`Name`].Value|[0]]' --output table

Extract only instance ID, type, state, and Name tag — 90% smaller response

Filter by tag value
aws ec2 describe-instances --filters 'Name=tag:Environment,Values=production' --query 'Reservations[*].Instances[*].{ID:InstanceId,Type:InstanceType,State:State.Name}' --output table

Find all production instances by tag:Environment=production

Server-side pagination
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

Wait for resource state (scripting)
aws ec2 wait instance-running --instance-ids i-1234567890abcdef0 && echo "Ready"

Block until instance reaches running state — no polling loops needed

Dry run (permission validation)
aws ec2 run-instances --image-id ami-0abcdef1234567890 --instance-type t3.micro --key-name my-key --dry-run

Validate IAM permissions and parameters without creating resources — essential before automation

Named profile switch
aws sts get-caller-identity --profile production

Verify which account/role a profile resolves to — always confirm before running commands in production

Region override
aws ec2 describe-instances --region eu-west-1 --profile staging

Combine --region and --profile for multi-account, multi-region operations

Count resources (shell pipeline)
aws ec2 describe-instances --filters 'Name=instance-state-name,Values=running' --query 'Reservations[*].Instances[*].InstanceId' --output text | wc -w

Count running instances across all regions — pipe CLI output to standard Unix tools

Generate skeleton config
aws ec2 run-instances --generate-cli-skeleton | tee template.json

Generate JSON template for any command — edit and pass back with --cli-input-json file://template.json

CLI Best Practices

  1. 1Never hardcode AWS credentials — use IAM roles (EC2/Lambda/ECS), aws configure, or environment variables
  2. 2Use --dry-run before destructive commands (ec2 terminate-instances, rds delete-db-instance)
  3. 3Set --output to control format: json for automation, table for humans, text for shell pipelines
  4. 4Master --query (JMESPath) — it reduces response size by 90%+ and eliminates post-processing code
  5. 5Use --profile to separate production, staging, and dev environments — never mix credentials
  6. 6Enable command completion: complete -C aws_completer aws — saves keystrokes and prevents typos
  7. 7Set AWS CLI pagination defaults in ~/.aws/config: cli_pager=less, max_items=100
  8. 8Use AWS CloudShell for quick commands — pre-authenticated, no credential setup needed
  9. 9Prefer aws s3api over aws s3 for scripting — consistent JSON output, no human-friendly formatting surprises
  10. 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.

People also search for

aws cli commands cheat sheetaws cli tutorialaws cli referenceaws cli examplesaws configure cliaws cli s3 commandsaws cli ec2 commandsaws cli lambda commandsaws cli iam commandsaws cli cheat sheet pdfaws cli query examplesaws cli jmespath tutorialaws cli paginationaws cli profiles