cheat-sheets

AWS CLI

The AWS CLI (v2) manages Amazon Web Services from the terminal. Compare Azure CLI (az) and gcloud (Google Cloud CLI); for infrastructure as code see Terraform. Provider-level notes (free tier, pitfalls, backups): Amazon Web Services.

Documentation: AWS CLI Command Reference


Install #

bash
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o awscliv2.zip
unzip awscliv2.zip && sudo ./aws/install
aws --version

Use awscli-exe-linux-aarch64.zip on ARM. macOS: brew install awscli (Homebrew). Windows: choco install awscli (Chocolatey) or the MSI. Update by re-running the installer with --update.

Credentials and Profiles #

COMMANDDESCRIPTION
aws configureSet access key, secret, region and output (stored in ~/.aws)
aws configure ssoSet up a profile for IAM Identity Center (SSO)
aws sso login --profile NAMESign in with SSO
aws sts get-caller-identityWho am I (best first check)
aws configure list-profilesList profiles
export AWS_PROFILE=NAMEUse a profile for the shell
aws s3 ls --profile NAME --region eu-west-2Per-command profile and region

Prefer SSO or short-lived roles over long-lived access keys. Never commit ~/.aws/credentials.

S3 #

COMMANDDESCRIPTION
aws s3 lsList buckets
aws s3 ls s3://bucket/prefix/ --recursive --human-readable --summarizeList with sizes
aws s3 cp file s3://bucket/Upload
aws s3 cp s3://bucket/file .Download
aws s3 sync ./dir s3://bucket/dir --deleteSync a directory (--delete removes extra remote files; add --dryrun first)
aws s3 rm s3://bucket/prefix/ --recursiveDelete
aws s3 mb s3://new-bucketCreate a bucket
aws s3 presign s3://bucket/file --expires-in 3600Temporary download URL

EC2 #

COMMANDDESCRIPTION
aws ec2 describe-instances --query "Reservations[].Instances[].[InstanceId,State.Name,PrivateIpAddress,Tags[?Key=='Name']|[0].Value]" --output tableInstances at a glance
aws ec2 start-instances --instance-ids i-0123Start (also stop-instances, terminate-instances)
aws ec2 describe-security-groups --output tableSecurity groups
aws ec2 describe-regions --query "Regions[].RegionName" --output textRegions

IAM, Kubernetes and Containers #

COMMANDDESCRIPTION
aws iam list-users --output tableList users
aws iam list-attached-user-policies --user-name NAMEA user’s policies
aws eks list-clustersList EKS clusters
aws eks update-kubeconfig --name CLUSTER --region eu-west-2Add the cluster to kubeconfig (Kubectl)
aws ecr get-login-password --region eu-west-2 | docker login --username AWS --password-stdin <ACCOUNT>.dkr.ecr.eu-west-2.amazonaws.comLog Docker in to ECR (Docker)
aws ssm get-parameter --name /path/key --with-decryption --query Parameter.Value --output textRead a parameter
aws secretsmanager get-secret-value --secret-id NAME --query SecretString --output textRead a secret

Output and Querying #

OPTIONDESCRIPTION
--output table|json|text|yamlOutput format
--query 'Items[].Name'JMESPath filter (client side)
--no-cli-pagerDo not page output (or export AWS_PAGER="")
--dry-runCheck permissions for many EC2 actions without doing them
aws <service> helpHelp for a service
aws <service> <command> helpHelp and examples for a command

Combine with jq for anything JMESPath makes awkward.

Not Verified #

Written from knowledge of AWS CLI v2 and not run against an account. Check aws <service> <command> help for current flags.

Search all sheets

Tip: / or Ctrl/Cmd+K to open, Esc to close.