AWS CLI v2 Quick Reference
A unified tool to manage AWS services from the terminal. This guide focuses on CLI v2 features, practical examples, and advanced patterns for experienced developers.
Quick Start
# Verify installation and version
aws --version
# Interactive configuration
aws configure # Access keys + region + output format
aws configure sso # IAM Identity Center (SSO) - recommended
# Verify identity
aws sts get-caller-identity # Shows Account, UserId, ARN
# Enable auto-prompt for command discovery
aws dynamodb --cli-auto-prompt
Power User Tips
# See all waiter commands for a service
aws ec2 wait help
# Generate command skeleton (fill in the blanks)
aws lambda create-function --generate-cli-skeleton > create-fn.json
# Create CLI alias for common commands
aws configure set cli_alias.whoami "sts get-caller-identity"
aws whoami # Now works!
# Disable pager for scripting
export AWS_PAGER=""
See Advanced Patterns for JMESPath mastery and automation tricks.
Global Options
| Flag |
Description |
--profile NAME |
Use named profile from ~/.aws/credentials |
--region REGION |
Override default region (e.g., us-east-1) |
--output FORMAT |
Output: json (default), text, table, yaml, yaml-stream |
--query EXPR |
Filter output using JMESPath expressions |
--no-paginate |
Disable auto-pagination (first page only) |
--dry-run |
Check permissions without executing (EC2, etc.) |
--debug |
Verbose HTTP/API debug logging |
--cli-auto-prompt |
Interactive parameter completion |
--no-cli-pager |
Disable output paging |
Decision Trees
Compute & Containers
Need compute?
├── Serverless functions ────────────► Lambda (references/lambda.md)
├── Docker containers
│ ├── Managed orchestration ───────► ECS (references/ecs.md)
│ ├── Kubernetes ──────────────────► EKS (references/eks.md)
│ └── Container registry ──────────► ECR (references/ecr.md)
└── Virtual machines ────────────────► EC2 (use aws ec2 commands)
Data & Storage
Need data storage?
├── Object/blob storage ─────────────► S3 (references/s3.md)
├── NoSQL (key-value/document) ──────► DynamoDB (references/dynamodb.md)
├── Relational SQL ──────────────────► Aurora/RDS (references/aurora.md)
├── Data catalog & ETL ──────────────► Glue (references/glue.md)
└── Data warehouse ──────────────────► Redshift (aws redshift commands)
Streaming & Messaging
Need streaming/messaging?
├── Kafka-compatible ────────────────► MSK (references/msk.md)
├── Real-time streams ───────────────► Kinesis (references/kinesis.md)
├── Message queues ──────────────────► SQS (aws sqs commands)
└── Pub/Sub notifications ───────────► SNS (aws sns commands)
Security & Access
Need security/access management?
├── Users, roles, policies ──────────► IAM (references/iam-security.md)
├── Secrets & credentials ───────────► Secrets Manager/SSM (references/private-parameters.md)
├── Private network access ──────────► VPC (references/vpc-networking.md)
└── Secure tunneling ────────────────► SSM/Bastion (references/bastion-tunneling.md)
Reference File Navigation
| Reference |
Description |
Key Triggers |
| Setup |
Installation, configuration, profiles, SSO |
install, configure, sso, profile |
| IAM & Security |
Roles, policies, STS, MFA, cross-account |
iam, role, policy, sts, assume-role |
| Lambda |
Functions, layers, aliases, URLs, events |
lambda, serverless, function |
| ECS |
Clusters, tasks, services, Fargate |
ecs, fargate, task, container |
| EKS |
Clusters, node groups, kubeconfig, IRSA |
eks, kubernetes, kubectl, k8s |
| ECR |
Repositories, auth, scanning, lifecycle |
ecr, docker, registry, image |
| S3 |
Buckets, objects, sync, presign, lifecycle |
s3, bucket, upload, sync |
| DynamoDB |
Tables, items, queries, streams, backups |
dynamodb, ddb, nosql |
| Aurora/RDS |
Clusters, serverless v2, cloning, blue-green |
rds, aurora, mysql, postgresql |
| Glue |
Catalog, crawlers, ETL jobs, workflows |
glue, etl, catalog, crawler |
| MSK |
Kafka clusters, serverless, configuration |
msk, kafka, streaming |
| Kinesis |
Data streams, Firehose, consumers |
kinesis, stream, firehose |
| Secrets & Params |
Parameter Store, Secrets Manager, rotation |
ssm, secrets, parameter, rotation |
| VPC & Networking |
VPCs, subnets, security groups, endpoints |
vpc, subnet, security-group, endpoint |
| Bastion & Tunneling |
SSM Session Manager, port forwarding |
bastion, tunnel, ssm, ssh |
| GitHub CI/CD |
OIDC, GitHub Actions, CodeBuild |
github, actions, oidc, cicd |
| Advanced Patterns |
JMESPath, waiters, skeletons, aliases |
jmespath, query, waiter, alias |
Environment Variables
| Variable |
Purpose |
Example |
AWS_ACCESS_KEY_ID |
Access key for authentication |
AKIAIOSFODNN7EXAMPLE |
AWS_SECRET_ACCESS_KEY |
Secret key for authentication |
wJalrXUtnFEMI/... |
AWS_SESSION_TOKEN |
Session token (temporary credentials) |
For STS assume-role |
AWS_PROFILE |
Named profile to use |
production |
AWS_REGION |
AWS region for requests |
us-west-2 |
AWS_DEFAULT_OUTPUT |
Default output format |
json, text, table |
AWS_PAGER |
Pager program (empty to disable) |
"" |
AWS_CONFIG_FILE |
Custom config file path |
~/.aws/config |
AWS_SHARED_CREDENTIALS_FILE |
Custom credentials file path |
~/.aws/credentials |
AWS_CA_BUNDLE |
Custom CA certificate bundle |
/path/to/cert.pem |
AWS_RETRY_MODE |
Retry mode |
standard, adaptive |
Credential Precedence
The CLI resolves credentials in this order (first match wins):
- Command-line options (
--profile, explicit credentials)
- Environment variables (
AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
- Web identity token (EKS IRSA, OIDC)
- SSO credentials (IAM Identity Center)
- Credentials file (
~/.aws/credentials)
- Config file (
~/.aws/config with credential_process)
- Container credentials (ECS task role)
- Instance metadata (EC2 instance profile, IMDSv2)
Common Patterns
Profile Switching
# Use specific profile for one command
aws s3 ls --profile production
# Set default profile for session
export AWS_PROFILE=production
# List configured profiles
aws configure list-profiles
Output Filtering with JMESPath
# Get specific fields
aws ec2 describe-instances \
--query 'Reservations[*].Instances[*].[InstanceId,State.Name]' \
--output table
# Filter running instances
aws ec2 describe-instances \
--query 'Reservations[*].Instances[?State.Name==`running`].InstanceId' \
--output text
Wait for Resource State
# Wait for instance to be running
aws ec2 wait instance-running --instance-ids i-1234567890abcdef0
# Wait for Lambda function update
aws lambda wait function-updated --function-name my-function
Best Practices
| Category |
Recommendation |
| Security |
Use aws configure sso over long-lived access keys |
| Security |
Use IAM roles for compute (EC2/Lambda/ECS) instead of embedded keys |
| Security |
Enable MFA for sensitive operations |
| Scripting |
Use --output json or --output text for parsing |
| Scripting |
Use --query to filter data and reduce output |
| Safety |
Use --dry-run before destructive operations |
| Performance |
Use --page-size to control memory on large lists |
| Regions |
Explicitly set region in scripts to avoid surprises |
| Cost |
Use lifecycle policies (S3/ECR) for automatic cleanup |
| Debugging |
Use --debug to see raw HTTP requests/responses |
Common Errors Quick Reference
| Error |
Cause |
Fix |
ExpiredToken |
Session credentials expired |
Run aws sso login or aws sts get-session-token |
AccessDenied |
Missing IAM permissions |
Check IAM policy; use --debug to see required action |
InvalidClientTokenId |
Invalid access key |
Verify AWS_ACCESS_KEY_ID or run aws configure |
UnauthorizedAccess |
Wrong region or account |
Check --region flag and aws sts get-caller-identity |
ThrottlingException |
API rate limit exceeded |
Add retry logic with exponential backoff |
NoCredentialProviders |
No credentials found |
Check credential chain; run aws configure list |
For detailed troubleshooting, see Setup.
When Not to Use
- AWS SDK code — For boto3, AWS SDK for JavaScript, etc., use programming documentation
- CloudFormation/Terraform — This skill covers CLI commands, not IaC templates
- Console UI steps — CLI-focused; use AWS documentation for console walkthroughs
- Pricing/billing — Use AWS pricing calculator or Cost Explorer documentation
Quick Command Reference
# Identity & Access
aws sts get-caller-identity
# → {"Account": "123456789012", "UserId": "AIDAEXAMPLE", "Arn": "arn:aws:iam::123456789012:user/dev"}
aws sts assume-role --role-arn arn:aws:iam::123456789012:role/Admin --role-session-name mysession
# → {"Credentials": {"AccessKeyId": "ASIA...", "SecretAccessKey": "...", "SessionToken": "..."}}
# S3
aws s3 ls
# → 2024-01-15 bucket-name-1
# → 2024-02-20 bucket-name-2
aws s3 sync ./local s3://bucket/prefix --delete
# Lambda
aws lambda invoke --function-name fn response.json
# → {"StatusCode": 200, "ExecutedVersion": "$LATEST"}
aws lambda update-function-code --function-name fn --zip-file fileb://code.zip
# → {"FunctionName": "fn", "LastModified": "2024-12-28T...", "State": "Active"}
# ECS
aws ecs list-clusters
# → {"clusterArns": ["arn:aws:ecs:us-east-1:123456789012:cluster/prod"]}
aws ecs update-service --cluster prod --service api --force-new-deployment
# EKS
aws eks update-kubeconfig --name my-cluster
# → Added new context arn:aws:eks:us-east-1:123456789012:cluster/my-cluster
aws eks list-clusters
# → {"clusters": ["my-cluster", "dev-cluster"]}
# Secrets
aws secretsmanager get-secret-value --secret-id prod/api/key --query SecretString --output text
# → sk_live_xxxxxxxxxxxxx
aws ssm get-parameter --name /app/prod/db/host --with-decryption --query Parameter.Value --output text
# → db.example.com
# Debugging
aws ssm start-session --target i-0123456789abcdef0
# → Starting session with SessionId: user-0a1b2c3d4e5f67890
1---2name: mastering-aws-cli3description: AWS CLI v2 quick-reference for experienced developers. Covers compute (Lambda, ECS, EKS), storage (S3, DynamoDB, Aurora), networking (VPC, SSM tunneling), security (IAM, Secrets Manager), and GitHub Actions CI/CD. Use when asked to "write aws commands", "debug aws access", "set up cross-account roles", "configure aws cli", "assume role", "S3 bucket operations", or "deploy to ECS".4license: MIT5---67# AWS CLI v2 Quick Reference89A unified tool to manage AWS services from the terminal. This guide focuses on CLI v2 features, practical examples, and advanced patterns for experienced developers.1011## Quick Start1213```bash14# Verify installation and version15aws --version1617# Interactive configuration18aws configure # Access keys + region + output format19aws configure sso # IAM Identity Center (SSO) - recommended2021# Verify identity22aws sts get-caller-identity # Shows Account, UserId, ARN2324# Enable auto-prompt for command discovery25aws dynamodb --cli-auto-prompt26```2728## Power User Tips2930```bash31# See all waiter commands for a service32aws ec2 wait help3334# Generate command skeleton (fill in the blanks)35aws lambda create-function --generate-cli-skeleton > create-fn.json3637# Create CLI alias for common commands38aws configure set cli_alias.whoami "sts get-caller-identity"39aws whoami # Now works!4041# Disable pager for scripting42export AWS_PAGER=""43```4445See [Advanced Patterns](references/advanced-patterns.md) for JMESPath mastery and automation tricks.4647## Global Options4849| Flag | Description |50|:-----|:------------|51| `--profile NAME` | Use named profile from `~/.aws/credentials` |52| `--region REGION` | Override default region (e.g., `us-east-1`) |53| `--output FORMAT` | Output: `json` (default), `text`, `table`, `yaml`, `yaml-stream` |54| `--query EXPR` | Filter output using JMESPath expressions |55| `--no-paginate` | Disable auto-pagination (first page only) |56| `--dry-run` | Check permissions without executing (EC2, etc.) |57| `--debug` | Verbose HTTP/API debug logging |58| `--cli-auto-prompt` | Interactive parameter completion |59| `--no-cli-pager` | Disable output paging |6061## Decision Trees6263### Compute & Containers64```65Need compute?66├── Serverless functions ────────────► Lambda (references/lambda.md)67├── Docker containers68│ ├── Managed orchestration ───────► ECS (references/ecs.md)69│ ├── Kubernetes ──────────────────► EKS (references/eks.md)70│ └── Container registry ──────────► ECR (references/ecr.md)71└── Virtual machines ────────────────► EC2 (use aws ec2 commands)72```7374### Data & Storage75```76Need data storage?77├── Object/blob storage ─────────────► S3 (references/s3.md)78├── NoSQL (key-value/document) ──────► DynamoDB (references/dynamodb.md)79├── Relational SQL ──────────────────► Aurora/RDS (references/aurora.md)80├── Data catalog & ETL ──────────────► Glue (references/glue.md)81└── Data warehouse ──────────────────► Redshift (aws redshift commands)82```8384### Streaming & Messaging85```86Need streaming/messaging?87├── Kafka-compatible ────────────────► MSK (references/msk.md)88├── Real-time streams ───────────────► Kinesis (references/kinesis.md)89├── Message queues ──────────────────► SQS (aws sqs commands)90└── Pub/Sub notifications ───────────► SNS (aws sns commands)91```9293### Security & Access94```95Need security/access management?96├── Users, roles, policies ──────────► IAM (references/iam-security.md)97├── Secrets & credentials ───────────► Secrets Manager/SSM (references/private-parameters.md)98├── Private network access ──────────► VPC (references/vpc-networking.md)99└── Secure tunneling ────────────────► SSM/Bastion (references/bastion-tunneling.md)100```101102## Reference File Navigation103104| Reference | Description | Key Triggers |105|:----------|:------------|:-------------|106| [Setup](references/setup.md) | Installation, configuration, profiles, SSO | `install`, `configure`, `sso`, `profile` |107| [IAM & Security](references/iam-security.md) | Roles, policies, STS, MFA, cross-account | `iam`, `role`, `policy`, `sts`, `assume-role` |108| [Lambda](references/lambda.md) | Functions, layers, aliases, URLs, events | `lambda`, `serverless`, `function` |109| [ECS](references/ecs.md) | Clusters, tasks, services, Fargate | `ecs`, `fargate`, `task`, `container` |110| [EKS](references/eks.md) | Clusters, node groups, kubeconfig, IRSA | `eks`, `kubernetes`, `kubectl`, `k8s` |111| [ECR](references/ecr.md) | Repositories, auth, scanning, lifecycle | `ecr`, `docker`, `registry`, `image` |112| [S3](references/s3.md) | Buckets, objects, sync, presign, lifecycle | `s3`, `bucket`, `upload`, `sync` |113| [DynamoDB](references/dynamodb.md) | Tables, items, queries, streams, backups | `dynamodb`, `ddb`, `nosql` |114| [Aurora/RDS](references/aurora.md) | Clusters, serverless v2, cloning, blue-green | `rds`, `aurora`, `mysql`, `postgresql` |115| [Glue](references/glue.md) | Catalog, crawlers, ETL jobs, workflows | `glue`, `etl`, `catalog`, `crawler` |116| [MSK](references/msk.md) | Kafka clusters, serverless, configuration | `msk`, `kafka`, `streaming` |117| [Kinesis](references/kinesis.md) | Data streams, Firehose, consumers | `kinesis`, `stream`, `firehose` |118| [Secrets & Params](references/private-parameters.md) | Parameter Store, Secrets Manager, rotation | `ssm`, `secrets`, `parameter`, `rotation` |119| [VPC & Networking](references/vpc-networking.md) | VPCs, subnets, security groups, endpoints | `vpc`, `subnet`, `security-group`, `endpoint` |120| [Bastion & Tunneling](references/bastion-tunneling.md) | SSM Session Manager, port forwarding | `bastion`, `tunnel`, `ssm`, `ssh` |121| [GitHub CI/CD](references/github-cicd.md) | OIDC, GitHub Actions, CodeBuild | `github`, `actions`, `oidc`, `cicd` |122| [Advanced Patterns](references/advanced-patterns.md) | JMESPath, waiters, skeletons, aliases | `jmespath`, `query`, `waiter`, `alias` |123124## Environment Variables125126| Variable | Purpose | Example |127|:---------|:--------|:--------|128| `AWS_ACCESS_KEY_ID` | Access key for authentication | `AKIAIOSFODNN7EXAMPLE` |129| `AWS_SECRET_ACCESS_KEY` | Secret key for authentication | `wJalrXUtnFEMI/...` |130| `AWS_SESSION_TOKEN` | Session token (temporary credentials) | For STS assume-role |131| `AWS_PROFILE` | Named profile to use | `production` |132| `AWS_REGION` | AWS region for requests | `us-west-2` |133| `AWS_DEFAULT_OUTPUT` | Default output format | `json`, `text`, `table` |134| `AWS_PAGER` | Pager program (empty to disable) | `""` |135| `AWS_CONFIG_FILE` | Custom config file path | `~/.aws/config` |136| `AWS_SHARED_CREDENTIALS_FILE` | Custom credentials file path | `~/.aws/credentials` |137| `AWS_CA_BUNDLE` | Custom CA certificate bundle | `/path/to/cert.pem` |138| `AWS_RETRY_MODE` | Retry mode | `standard`, `adaptive` |139140## Credential Precedence141142The CLI resolves credentials in this order (first match wins):1431441. **Command-line options** (`--profile`, explicit credentials)1452. **Environment variables** (`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`)1463. **Web identity token** (EKS IRSA, OIDC)1474. **SSO credentials** (IAM Identity Center)1485. **Credentials file** (`~/.aws/credentials`)1496. **Config file** (`~/.aws/config` with `credential_process`)1507. **Container credentials** (ECS task role)1518. **Instance metadata** (EC2 instance profile, IMDSv2)152153## Common Patterns154155### Profile Switching156```bash157# Use specific profile for one command158aws s3 ls --profile production159160# Set default profile for session161export AWS_PROFILE=production162163# List configured profiles164aws configure list-profiles165```166167### Output Filtering with JMESPath168```bash169# Get specific fields170aws ec2 describe-instances \171 --query 'Reservations[*].Instances[*].[InstanceId,State.Name]' \172 --output table173174# Filter running instances175aws ec2 describe-instances \176 --query 'Reservations[*].Instances[?State.Name==`running`].InstanceId' \177 --output text178```179180### Wait for Resource State181```bash182# Wait for instance to be running183aws ec2 wait instance-running --instance-ids i-1234567890abcdef0184185# Wait for Lambda function update186aws lambda wait function-updated --function-name my-function187```188189## Best Practices190191| Category | Recommendation |192|:---------|:---------------|193| **Security** | Use `aws configure sso` over long-lived access keys |194| **Security** | Use IAM roles for compute (EC2/Lambda/ECS) instead of embedded keys |195| **Security** | Enable MFA for sensitive operations |196| **Scripting** | Use `--output json` or `--output text` for parsing |197| **Scripting** | Use `--query` to filter data and reduce output |198| **Safety** | Use `--dry-run` before destructive operations |199| **Performance** | Use `--page-size` to control memory on large lists |200| **Regions** | Explicitly set region in scripts to avoid surprises |201| **Cost** | Use lifecycle policies (S3/ECR) for automatic cleanup |202| **Debugging** | Use `--debug` to see raw HTTP requests/responses |203204## Common Errors Quick Reference205206| Error | Cause | Fix |207|:------|:------|:----|208| `ExpiredToken` | Session credentials expired | Run `aws sso login` or `aws sts get-session-token` |209| `AccessDenied` | Missing IAM permissions | Check IAM policy; use `--debug` to see required action |210| `InvalidClientTokenId` | Invalid access key | Verify `AWS_ACCESS_KEY_ID` or run `aws configure` |211| `UnauthorizedAccess` | Wrong region or account | Check `--region` flag and `aws sts get-caller-identity` |212| `ThrottlingException` | API rate limit exceeded | Add retry logic with exponential backoff |213| `NoCredentialProviders` | No credentials found | Check credential chain; run `aws configure list` |214215For detailed troubleshooting, see [Setup](references/setup.md#troubleshooting).216217## When Not to Use218219- **AWS SDK code** — For boto3, AWS SDK for JavaScript, etc., use programming documentation220- **CloudFormation/Terraform** — This skill covers CLI commands, not IaC templates221- **Console UI steps** — CLI-focused; use AWS documentation for console walkthroughs222- **Pricing/billing** — Use AWS pricing calculator or Cost Explorer documentation223224## Quick Command Reference225226```bash227# Identity & Access228aws sts get-caller-identity229# → {"Account": "123456789012", "UserId": "AIDAEXAMPLE", "Arn": "arn:aws:iam::123456789012:user/dev"}230231aws sts assume-role --role-arn arn:aws:iam::123456789012:role/Admin --role-session-name mysession232# → {"Credentials": {"AccessKeyId": "ASIA...", "SecretAccessKey": "...", "SessionToken": "..."}}233234# S3235aws s3 ls236# → 2024-01-15 bucket-name-1237# → 2024-02-20 bucket-name-2238239aws s3 sync ./local s3://bucket/prefix --delete240241# Lambda242aws lambda invoke --function-name fn response.json243# → {"StatusCode": 200, "ExecutedVersion": "$LATEST"}244245aws lambda update-function-code --function-name fn --zip-file fileb://code.zip246# → {"FunctionName": "fn", "LastModified": "2024-12-28T...", "State": "Active"}247248# ECS249aws ecs list-clusters250# → {"clusterArns": ["arn:aws:ecs:us-east-1:123456789012:cluster/prod"]}251252aws ecs update-service --cluster prod --service api --force-new-deployment253254# EKS255aws eks update-kubeconfig --name my-cluster256# → Added new context arn:aws:eks:us-east-1:123456789012:cluster/my-cluster257258aws eks list-clusters259# → {"clusters": ["my-cluster", "dev-cluster"]}260261# Secrets262aws secretsmanager get-secret-value --secret-id prod/api/key --query SecretString --output text263# → sk_live_xxxxxxxxxxxxx264265aws ssm get-parameter --name /app/prod/db/host --with-decryption --query Parameter.Value --output text266# → db.example.com267268# Debugging269aws ssm start-session --target i-0123456789abcdef0270# → Starting session with SessionId: user-0a1b2c3d4e5f67890271```