Written for AWS CLI version 2. aws login needs 2.32.0 or later. IDs, names, ARNs and regions are examples, so swap in your own, and add --profile or --region to any command to pick an account or region. Queries are written with double quotes outside and single quotes inside, which works in bash, zsh, PowerShell and Command Prompt.
Official links: AWS website, AWS CLI user guide, AWS CLI command reference.
Setup and help #
-
Show the AWS CLI versionLinux, macOS, Windows
aws --version -
Get help for a serviceLinux, macOS, Windows
aws ec2 help -
Get help for one commandLinux, macOS, Windows
aws ec2 describe-instances help -
Get help on a topic, such as filters or quotingLinux, macOS, Windows
aws help topics -
Build a command step by step, with suggestions as you typeLinux, macOS, Windows
aws ec2 describe-instances --cli-auto-prompt -
Turn on tab completion in bashLinux, macOS
complete -C aws_completer aws -
Turn on tab completion in zshLinux, macOS
autoload bashcompinit && bashcompinit && complete -C aws_completer aws -
Show an example of every option a command takes, as JSONLinux, macOS, Windows
aws ec2 run-instances --generate-cli-skeleton -
Run a command with its options read from a JSON fileLinux, macOS, Windows
aws ec2 run-instances --cli-input-json file://input.json
Sign in and profiles #
-
Sign in with your AWS console username and password, in the browserLinux, macOS, Windows
aws login -
Sign in on a remote machine over SSH, by pasting a codeLinux, macOS, Windows
aws login --remote -
Sign in to a named profileLinux, macOS, Windows
aws login --profile dev -
Sign out and delete the saved sign-inLinux, macOS, Windows
aws logout -
Set up a profile for IAM Identity Center (SSO)Linux, macOS, Windows
aws configure sso -
Sign in with IAM Identity Center (SSO)Linux, macOS, Windows
aws sso login --profile dev -
Sign in with SSO on a machine with no browserLinux, macOS, Windows
aws sso login --profile dev --use-device-code -
Sign out of IAM Identity Center (SSO)Linux, macOS, Windows
aws sso logout -
Set up the default profile with an access keyLinux, macOS, Windows
aws configureWarning: This saves a long-term access key in plain text in ~/.aws/credentials. Prefer aws login or aws configure sso where you can.
-
Set up a named profile with an access keyLinux, macOS, Windows
aws configure --profile devWarning: This saves a long-term access key in plain text in ~/.aws/credentials. Prefer aws login or aws configure sso where you can.
-
List your profilesLinux, macOS, Windows
aws configure list-profiles -
Show where each setting comes from: profile, file or environmentLinux, macOS, Windows
aws configure list -
Show one setting from a profileLinux, macOS, Windows
aws configure get region --profile dev -
Change one setting in a profileLinux, macOS, Windows
aws configure set region eu-west-1 --profile dev -
Set a profile's default output formatLinux, macOS, Windows
aws configure set output table --profile dev -
Add a profile that assumes a role using another profileLinux, macOS, Windows
aws configure set role_arn arn:aws:iam::123456789012:role/Admin --profile admin aws configure set source_profile dev --profile admin -
Run one command as a profileLinux, macOS, Windows
aws s3 ls --profile dev -
Run one command in another regionLinux, macOS, Windows
aws ec2 describe-instances --region eu-west-1 -
Use a profile for every command in this terminalLinux, macOS
export AWS_PROFILE=devWindows$env:AWS_PROFILE = "dev" -
Use a region for every command in this terminalLinux, macOS
export AWS_REGION=eu-west-1Windows$env:AWS_REGION = "eu-west-1" -
Go back to the default profile in this terminalLinux, macOS
unset AWS_PROFILEWindowsRemove-Item Env:AWS_PROFILE -
Print your current sign-in as environment variables, for another toolLinux, macOS, Windows
aws configure export-credentials --profile dev --format envWarning: This prints secret keys to the screen. Don't paste the output anywhere it could be saved or shared.
-
Load your current sign-in into this terminal's environmentLinux, macOS
eval "$(aws configure export-credentials --profile dev --format env)"
Identity and accounts #
-
Show which account and user or role you're signed in asLinux, macOS, Windows
aws sts get-caller-identity -
Show just the account numberLinux, macOS, Windows
aws sts get-caller-identity --query Account --output text -
Get temporary keys for a roleLinux, macOS, Windows
aws sts assume-role --role-arn arn:aws:iam::123456789012:role/Admin --role-session-name my-sessionWarning: The output includes a secret key and session token in plain text.
-
Get temporary keys with an MFA codeLinux, macOS, Windows
aws sts get-session-token --serial-number arn:aws:iam::123456789012:mfa/my-phone --token-code 123456Warning: The output includes a secret key and session token in plain text.
-
Decode an "encoded authorization failure message"Linux, macOS, Windows
aws sts decode-authorization-message --encoded-message AbCdEf123... --query DecodedMessage --output text -
Show the account's aliasLinux, macOS, Windows
aws iam list-account-aliases -
List the accounts in your organizationLinux, macOS, Windows
aws organizations list-accounts --query "Accounts[].[Id,Name,Status]" --output table -
List the regions turned on for your accountLinux, macOS, Windows
aws ec2 describe-regions --query "Regions[].RegionName" --output text -
List the Availability Zones in a regionLinux, macOS, Windows
aws ec2 describe-availability-zones --region eu-west-1 --query "AvailabilityZones[].ZoneName" --output text
Output, filtering and paging #
-
Show output as a tableLinux, macOS, Windows
aws ec2 describe-instances --output table -
Show output as plain text, one row per line, for scriptsLinux, macOS, Windows
aws ec2 describe-instances --output text -
Show output as YAMLLinux, macOS, Windows
aws ec2 describe-instances --output yaml -
Pick fields out of the output with a queryLinux, macOS, Windows
aws ec2 describe-instances --query "Reservations[].Instances[].[InstanceId,InstanceType,State.Name]" --output table -
Name the columns in a tableLinux, macOS, Windows
aws ec2 describe-instances --query "Reservations[].Instances[].{ID:InstanceId,Type:InstanceType,State:State.Name}" --output table -
Keep only matching items with a queryLinux, macOS, Windows
aws ec2 describe-instances --query "Reservations[].Instances[?State.Name=='running'].InstanceId" --output text -
Filter on the AWS side, which is faster for big listsLinux, macOS, Windows
aws ec2 describe-instances --filters Name=instance-state-name,Values=running -
Filter by tagLinux, macOS, Windows
aws ec2 describe-instances --filters Name=tag:Environment,Values=prod -
Count the resultsLinux, macOS, Windows
aws ec2 describe-instances --query "length(Reservations[].Instances[])" -
Sort the results by a fieldLinux, macOS, Windows
aws ec2 describe-snapshots --owner-ids self --query "sort_by(Snapshots, &StartTime)[].[SnapshotId,StartTime]" --output text -
Show only the first few resultsLinux, macOS, Windows
aws ec2 describe-instances --max-items 10 -
Get the next page after --max-itemsLinux, macOS, Windows
aws ec2 describe-instances --max-items 10 --starting-token eyJOZXh0VG9rZW4iOi... -
Turn off the pager so output prints straight to the terminalLinux, macOS, Windows
aws ec2 describe-instances --no-cli-pager -
Turn off the pager for every command in this terminalLinux, macOS
export AWS_PAGER=""Windows$env:AWS_PAGER = "" -
Turn off the pager for goodLinux, macOS, Windows
aws configure set cli_pager "" -
Check you have permission without changing anythingLinux, macOS, Windows
aws ec2 run-instances --image-id ami-0abc123def4567890 --instance-type t3.micro --dry-run -
Wait until something is ready, such as an instance runningLinux, macOS, Windows
aws ec2 wait instance-running --instance-ids i-0abc123def4567890
S3 storage #
-
List your bucketsLinux, macOS, Windows
aws s3 ls -
List the files in a bucketLinux, macOS, Windows
aws s3 ls s3://my-bucket/ -
List every file in a bucket, with sizes and a totalLinux, macOS, Windows
aws s3 ls s3://my-bucket --recursive --human-readable --summarize -
Make a bucketLinux, macOS, Windows
aws s3 mb s3://my-bucket --region eu-west-1 -
Upload a fileLinux, macOS, Windows
aws s3 cp report.csv s3://my-bucket/reports/2026.csv -
Download a fileLinux, macOS, Windows
aws s3 cp s3://my-bucket/reports/2026.csv report.csv -
Upload a folderLinux, macOS, Windows
aws s3 cp ./site s3://my-bucket/site/ --recursive -
Copy a file between bucketsLinux, macOS, Windows
aws s3 cp s3://my-bucket/reports/2026.csv s3://my-backup-bucket/reports/2026.csv -
Print a file to the screenLinux, macOS, Windows
aws s3 cp s3://my-bucket/reports/2026.csv - -
Rename or move a fileLinux, macOS, Windows
aws s3 mv s3://my-bucket/reports/2026.csv s3://my-bucket/archive/2026.csv -
Sync a folder up to a bucket, copying only what changedLinux, macOS, Windows
aws s3 sync ./site s3://my-bucket/site/ -
Sync a bucket down to a folderLinux, macOS, Windows
aws s3 sync s3://my-bucket/site/ ./site -
Sync and delete files in the bucket that aren't in the folderLinux, macOS, Windows
aws s3 sync ./site s3://my-bucket/site/ --deleteWarning: Deletes files from the bucket. Run it with --dryrun first to see what it would remove.
-
Show what a sync would do without doing itLinux, macOS, Windows
aws s3 sync ./site s3://my-bucket/site/ --dryrun -
Sync only some filesLinux, macOS, Windows
aws s3 sync ./site s3://my-bucket/site/ --exclude "*" --include "*.html" -
Delete a fileLinux, macOS, Windows
aws s3 rm s3://my-bucket/reports/2026.csvWarning: Deleted files can't be got back unless versioning is on.
-
Delete everything under a folder in a bucketLinux, macOS, Windows
aws s3 rm s3://my-bucket/site/ --recursiveWarning: Deletes every file under that prefix. Run it with --dryrun first.
-
Delete an empty bucketLinux, macOS, Windows
aws s3 rb s3://my-bucket -
Delete a bucket and everything in itLinux, macOS, Windows
aws s3 rb s3://my-bucket --forceWarning: Deletes every file and then the bucket, with no undo. Old versions in a versioned bucket aren't removed, so the bucket delete fails until they're gone.
-
Make a link to download a file that expires in an hourLinux, macOS, Windows
aws s3 presign s3://my-bucket/reports/2026.csv --expires-in 3600Warning: Anyone with the link can download the file until it expires.
-
Show a file's size, type and metadataLinux, macOS, Windows
aws s3api head-object --bucket my-bucket --key reports/2026.csv -
Show which region a bucket is inLinux, macOS, Windows
aws s3api get-bucket-location --bucket my-bucket -
Turn on versioning for a bucketLinux, macOS, Windows
aws s3api put-bucket-versioning --bucket my-bucket --versioning-configuration Status=Enabled -
List every version of a fileLinux, macOS, Windows
aws s3api list-object-versions --bucket my-bucket --prefix reports/2026.csv -
Block all public access to a bucketLinux, macOS, Windows
aws s3api put-public-access-block --bucket my-bucket --public-access-block-configuration BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true -
Show a bucket's policyLinux, macOS, Windows
aws s3api get-bucket-policy --bucket my-bucket --query Policy --output text -
Apply a bucket policy from a fileLinux, macOS, Windows
aws s3api put-bucket-policy --bucket my-bucket --policy file://input.json -
Show a bucket's default encryptionLinux, macOS, Windows
aws s3api get-bucket-encryption --bucket my-bucket -
Show a bucket's tagsLinux, macOS, Windows
aws s3api get-bucket-tagging --bucket my-bucket -
Upload with a storage class, such as Infrequent AccessLinux, macOS, Windows
aws s3 cp report.csv s3://my-bucket/reports/2026.csv --storage-class STANDARD_IA
EC2 instances #
-
List your instances with their ID, type, state and nameLinux, macOS, Windows
aws ec2 describe-instances --query "Reservations[].Instances[].[InstanceId,InstanceType,State.Name,Tags[?Key=='Name']|[0].Value]" --output table -
List running instancesLinux, macOS, Windows
aws ec2 describe-instances --filters Name=instance-state-name,Values=running --query "Reservations[].Instances[].InstanceId" --output text -
Show everything about one instanceLinux, macOS, Windows
aws ec2 describe-instances --instance-ids i-0abc123def4567890 -
Show an instance's public and private IP addressesLinux, macOS, Windows
aws ec2 describe-instances --instance-ids i-0abc123def4567890 --query "Reservations[].Instances[].[PublicIpAddress,PrivateIpAddress]" --output text -
Find an instance by its Name tagLinux, macOS, Windows
aws ec2 describe-instances --filters Name=tag:Name,Values=web-1 --query "Reservations[].Instances[].InstanceId" --output text -
Start an instanceLinux, macOS, Windows
aws ec2 start-instances --instance-ids i-0abc123def4567890 -
Stop an instanceLinux, macOS, Windows
aws ec2 stop-instances --instance-ids i-0abc123def4567890 -
Reboot an instanceLinux, macOS, Windows
aws ec2 reboot-instances --instance-ids i-0abc123def4567890 -
Terminate an instanceLinux, macOS, Windows
aws ec2 terminate-instances --instance-ids i-0abc123def4567890Warning: Terminating deletes the instance, and any volumes set to delete on termination, with no undo.
-
Stop people terminating an instance by mistakeLinux, macOS, Windows
aws ec2 modify-instance-attribute --instance-id i-0abc123def4567890 --disable-api-termination -
Launch an instanceLinux, macOS, Windows
aws ec2 run-instances --image-id ami-0abc123def4567890 --instance-type t3.micro --key-name my-key --subnet-id subnet-0abc123def4567890 --security-group-ids sg-0abc123def4567890 --tag-specifications "ResourceType=instance,Tags=[{Key=Name,Value=web-1}]" -
Launch an instance with a start-up scriptLinux, macOS, Windows
aws ec2 run-instances --image-id ami-0abc123def4567890 --instance-type t3.micro --user-data file://setup.sh -
Change an instance's type (stop it first)Linux, macOS, Windows
aws ec2 modify-instance-attribute --instance-id i-0abc123def4567890 --instance-type Value=t3.large -
Check an instance's status checksLinux, macOS, Windows
aws ec2 describe-instance-status --instance-ids i-0abc123def4567890 -
Show an instance's console output, to debug a bootLinux, macOS, Windows
aws ec2 get-console-output --instance-id i-0abc123def4567890 --latest --output text -
Add or change a tagLinux, macOS, Windows
aws ec2 create-tags --resources i-0abc123def4567890 --tags Key=Environment,Value=prod -
Find the latest Amazon Linux 2023 imageLinux, macOS, Windows
aws ssm get-parameter --name /aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-x86_64 --query Parameter.Value --output text -
Find the latest Ubuntu 24.04 imageLinux, macOS, Windows
aws ssm get-parameter --name /aws/service/canonical/ubuntu/server/24.04/stable/current/amd64/hvm/ebs-gp3/ami-id --query Parameter.Value --output text -
List your own imagesLinux, macOS, Windows
aws ec2 describe-images --owners self --query "Images[].[ImageId,Name,CreationDate]" --output table -
Make an image from an instanceLinux, macOS, Windows
aws ec2 create-image --instance-id i-0abc123def4567890 --name web-1-backup -
List instance types with their CPUs and memoryLinux, macOS, Windows
aws ec2 describe-instance-types --filters Name=current-generation,Values=true --query "InstanceTypes[].[InstanceType,VCpuInfo.DefaultVCpus,MemoryInfo.SizeInMiB]" --output table -
Make a key pair and save the private keyLinux, macOS, Windows
aws ec2 create-key-pair --key-name my-key --query KeyMaterial --output text > my-key.pem -
List key pairsLinux, macOS, Windows
aws ec2 describe-key-pairs -
Delete a key pairLinux, macOS, Windows
aws ec2 delete-key-pair --key-name my-key
VPCs and security groups #
-
List VPCsLinux, macOS, Windows
aws ec2 describe-vpcs --query "Vpcs[].[VpcId,CidrBlock,IsDefault]" --output table -
List subnets in a VPCLinux, macOS, Windows
aws ec2 describe-subnets --filters Name=vpc-id,Values=vpc-0abc123def4567890 --query "Subnets[].[SubnetId,CidrBlock,AvailabilityZone]" --output table -
Make a VPCLinux, macOS, Windows
aws ec2 create-vpc --cidr-block 10.0.0.0/16 -
Make a subnetLinux, macOS, Windows
aws ec2 create-subnet --vpc-id vpc-0abc123def4567890 --cidr-block 10.0.1.0/24 --availability-zone eu-west-1a -
List route tables in a VPCLinux, macOS, Windows
aws ec2 describe-route-tables --filters Name=vpc-id,Values=vpc-0abc123def4567890 -
List internet gatewaysLinux, macOS, Windows
aws ec2 describe-internet-gateways -
List NAT gatewaysLinux, macOS, Windows
aws ec2 describe-nat-gateways -
List security groupsLinux, macOS, Windows
aws ec2 describe-security-groups --query "SecurityGroups[].[GroupId,GroupName,VpcId]" --output table -
Show a security group's rulesLinux, macOS, Windows
aws ec2 describe-security-group-rules --filters Name=group-id,Values=sg-0abc123def4567890 -
Make a security groupLinux, macOS, Windows
aws ec2 create-security-group --group-name web-sg --description "Web servers" --vpc-id vpc-0abc123def4567890 -
Allow a port in from one addressLinux, macOS, Windows
aws ec2 authorize-security-group-ingress --group-id sg-0abc123def4567890 --protocol tcp --port 443 --cidr 203.0.113.10/32 -
Allow HTTPS in from anywhereLinux, macOS, Windows
aws ec2 authorize-security-group-ingress --group-id sg-0abc123def4567890 --protocol tcp --port 443 --cidr 0.0.0.0/0 -
Remove a ruleLinux, macOS, Windows
aws ec2 revoke-security-group-ingress --group-id sg-0abc123def4567890 --protocol tcp --port 443 --cidr 203.0.113.10/32 -
Allow SSH from your own public IP addressLinux, macOS
aws ec2 authorize-security-group-ingress --group-id sg-0abc123def4567890 --protocol tcp --port 22 --cidr "$(curl -s https://checkip.amazonaws.com)/32" -
Find security groups open to the whole internetLinux, macOS, Windows
aws ec2 describe-security-groups --filters Name=ip-permission.cidr,Values=0.0.0.0/0 --query "SecurityGroups[].[GroupId,GroupName]" --output table -
Get a new Elastic IP addressLinux, macOS, Windows
aws ec2 allocate-address -
Attach an Elastic IP to an instanceLinux, macOS, Windows
aws ec2 associate-address --instance-id i-0abc123def4567890 --allocation-id eipalloc-0abc123def4567890 -
List Elastic IPs, including unattached ones you're paying forLinux, macOS, Windows
aws ec2 describe-addresses --query "Addresses[].[PublicIp,AllocationId,InstanceId]" --output table -
Release an Elastic IPLinux, macOS, Windows
aws ec2 release-address --allocation-id eipalloc-0abc123def4567890Warning: The address goes back to AWS and you can't get the same one back.
-
Turn on VPC flow logs to CloudWatchLinux, macOS, Windows
aws ec2 create-flow-logs --resource-type VPC --resource-ids vpc-0abc123def4567890 --traffic-type ALL --log-group-name vpc-flow-logs --deliver-logs-permission-arn arn:aws:iam::123456789012:role/Admin
EBS volumes and snapshots #
-
List volumesLinux, macOS, Windows
aws ec2 describe-volumes --query "Volumes[].[VolumeId,Size,VolumeType,State]" --output table -
List volumes that aren't attached to anythingLinux, macOS, Windows
aws ec2 describe-volumes --filters Name=status,Values=available --query "Volumes[].[VolumeId,Size,CreateTime]" --output table -
Make a volumeLinux, macOS, Windows
aws ec2 create-volume --availability-zone eu-west-1a --size 100 --volume-type gp3 -
Attach a volume to an instanceLinux, macOS, Windows
aws ec2 attach-volume --volume-id vol-0abc123def4567890 --instance-id i-0abc123def4567890 --device /dev/sdf -
Detach a volumeLinux, macOS, Windows
aws ec2 detach-volume --volume-id vol-0abc123def4567890 -
Make a volume biggerLinux, macOS, Windows
aws ec2 modify-volume --volume-id vol-0abc123def4567890 --size 100 -
Delete a volumeLinux, macOS, Windows
aws ec2 delete-volume --volume-id vol-0abc123def4567890Warning: The data on it is gone for good unless you have a snapshot.
-
Take a snapshot of a volumeLinux, macOS, Windows
aws ec2 create-snapshot --volume-id vol-0abc123def4567890 --description "Web servers" -
List your snapshotsLinux, macOS, Windows
aws ec2 describe-snapshots --owner-ids self --query "Snapshots[].[SnapshotId,VolumeId,StartTime,State]" --output table -
Make a volume from a snapshotLinux, macOS, Windows
aws ec2 create-volume --snapshot-id snap-0abc123def4567890 --availability-zone eu-west-1a -
Copy a snapshot to another regionLinux, macOS, Windows
aws ec2 copy-snapshot --source-region eu-west-1 --source-snapshot-id snap-0abc123def4567890 --region us-east-1 -
Delete a snapshotLinux, macOS, Windows
aws ec2 delete-snapshot --snapshot-id snap-0abc123def4567890Warning: Deleted snapshots can't be got back.
IAM users, roles and policies #
-
List usersLinux, macOS, Windows
aws iam list-users --query "Users[].[UserName,CreateDate]" --output table -
List rolesLinux, macOS, Windows
aws iam list-roles --query "Roles[].[RoleName,Arn]" --output table -
Show a role, including who can assume itLinux, macOS, Windows
aws iam get-role --role-name Admin -
Make a userLinux, macOS, Windows
aws iam create-user --user-name alice -
Add a user to a groupLinux, macOS, Windows
aws iam add-user-to-group --user-name alice --group-name Developers -
List a user's groupsLinux, macOS, Windows
aws iam list-groups-for-user --user-name alice -
Attach a managed policy to a userLinux, macOS, Windows
aws iam attach-user-policy --user-name alice --policy-arn arn:aws:iam::aws:policy/ReadOnlyAccess -
Attach a managed policy to a roleLinux, macOS, Windows
aws iam attach-role-policy --role-name Admin --policy-arn arn:aws:iam::aws:policy/ReadOnlyAccess -
Detach a policy from a roleLinux, macOS, Windows
aws iam detach-role-policy --role-name Admin --policy-arn arn:aws:iam::aws:policy/ReadOnlyAccess -
List the managed policies on a roleLinux, macOS, Windows
aws iam list-attached-role-policies --role-name Admin -
List the inline policies on a roleLinux, macOS, Windows
aws iam list-role-policies --role-name Admin -
Make a role from a trust policy fileLinux, macOS, Windows
aws iam create-role --role-name Admin --assume-role-policy-document file://input.json -
Make a policy from a JSON fileLinux, macOS, Windows
aws iam create-policy --policy-name ReadReports --policy-document file://input.json -
Show what a managed policy allowsLinux, macOS, Windows
aws iam get-policy-version --policy-arn arn:aws:iam::aws:policy/ReadOnlyAccess --version-id v1 -
Test whether a role is allowed to do somethingLinux, macOS, Windows
aws iam simulate-principal-policy --policy-source-arn arn:aws:iam::123456789012:role/Admin --action-names s3:GetObject --resource-arns "arn:aws:s3:::my-bucket/*" -
List a user's access keysLinux, macOS, Windows
aws iam list-access-keys --user-name alice -
Show when an access key was last usedLinux, macOS, Windows
aws iam get-access-key-last-used --access-key-id AKIAIOSFODNN7EXAMPLE -
Make an access key for a userLinux, macOS, Windows
aws iam create-access-key --user-name aliceWarning: The secret key is shown once, in plain text. Store it somewhere safe, and prefer short-term sign-in where you can.
-
Turn off an access keyLinux, macOS, Windows
aws iam update-access-key --user-name alice --access-key-id AKIAIOSFODNN7EXAMPLE --status Inactive -
Delete an access keyLinux, macOS, Windows
aws iam delete-access-key --user-name alice --access-key-id AKIAIOSFODNN7EXAMPLEWarning: Anything still using the key stops working straight away.
-
List a user's MFA devicesLinux, macOS, Windows
aws iam list-mfa-devices --user-name alice -
Download the credential report for every userLinux, macOS
aws iam generate-credential-report aws iam get-credential-report --query Content --output text | base64 --decode > credential-report.csv -
Show the account's password policyLinux, macOS, Windows
aws iam get-account-password-policy -
Show the account's IAM usage and limitsLinux, macOS, Windows
aws iam get-account-summary
Lambda functions #
-
List functionsLinux, macOS, Windows
aws lambda list-functions --query "Functions[].[FunctionName,Runtime,LastModified]" --output table -
Show a function's settingsLinux, macOS, Windows
aws lambda get-function-configuration --function-name my-function -
Run a function and save what it returnsLinux, macOS, Windows
aws lambda invoke --function-name my-function --cli-binary-format raw-in-base64-out --payload file://input.json response.json -
Run a function and show its last 4 KB of logsLinux, macOS
aws lambda invoke --function-name my-function --log-type Tail --query LogResult --output text response.json | base64 --decode -
Update a function's code from a zip fileLinux, macOS, Windows
aws lambda update-function-code --function-name my-function --zip-file fileb://function.zip -
Update a function's environment variablesLinux, macOS, Windows
aws lambda update-function-configuration --function-name my-function --environment "Variables={LOG_LEVEL=debug}" -
Change a function's memory and timeoutLinux, macOS, Windows
aws lambda update-function-configuration --function-name my-function --memory-size 512 --timeout 30 -
Publish a new versionLinux, macOS, Windows
aws lambda publish-version --function-name my-function -
Point an alias at a versionLinux, macOS, Windows
aws lambda update-alias --function-name my-function --name live --function-version 3 -
Make a function URL anyone can callLinux, macOS, Windows
aws lambda create-function-url-config --function-name my-function --auth-type NONEWarning: With NONE, anyone with the URL can run the function. You'll also need a resource policy that lets the public call it.
-
Delete a functionLinux, macOS, Windows
aws lambda delete-function --function-name my-functionWarning: Deletes the function and every version of it.
CloudWatch logs and metrics #
-
List log groupsLinux, macOS, Windows
aws logs describe-log-groups --query "logGroups[].[logGroupName,storedBytes]" --output table -
Follow a log group liveLinux, macOS, Windows
aws logs tail /aws/lambda/my-function --follow -
Show the last hour of a log groupLinux, macOS, Windows
aws logs tail /aws/lambda/my-function --since 1h -
Show log lines that match a wordLinux, macOS, Windows
aws logs tail /aws/lambda/my-function --since 1d --filter-pattern ERROR -
Search a log group across all its streamsLinux, macOS, Windows
aws logs filter-log-events --log-group-name /aws/lambda/my-function --filter-pattern ERROR -
Keep a log group's logs for 30 days onlyLinux, macOS, Windows
aws logs put-retention-policy --log-group-name /aws/lambda/my-function --retention-in-days 30 -
Find log groups that keep logs foreverLinux, macOS, Windows
aws logs describe-log-groups --query "logGroups[?retentionInDays==null].logGroupName" --output text -
Run a Logs Insights queryLinux, macOS, Windows
aws logs start-query --log-group-name /aws/lambda/my-function --start-time 1793836800 --end-time 1793923200 --query-string "fields @timestamp, @message | filter @message like /ERROR/ | limit 20" -
Get a Logs Insights query's resultsLinux, macOS, Windows
aws logs get-query-results --query-id 12ab3456-12ab-123a-789e-1234567890ab -
Delete a log groupLinux, macOS, Windows
aws logs delete-log-group --log-group-name /aws/lambda/my-functionWarning: Deletes every log in the group.
-
List alarms that are going offLinux, macOS, Windows
aws cloudwatch describe-alarms --state-value ALARM --query "MetricAlarms[].[AlarmName,StateReason]" --output table -
List the metrics for an instanceLinux, macOS, Windows
aws cloudwatch list-metrics --namespace AWS/EC2 --dimensions Name=InstanceId,Value=i-0abc123def4567890 -
Get an instance's average CPU over a dayLinux, macOS, Windows
aws cloudwatch get-metric-statistics --namespace AWS/EC2 --metric-name CPUUtilization --dimensions Name=InstanceId,Value=i-0abc123def4567890 --start-time 2026-11-17T00:00:00Z --end-time 2026-11-18T00:00:00Z --period 3600 --statistics Average -
Make an alarm for high CPULinux, macOS, Windows
aws cloudwatch put-metric-alarm --alarm-name web-1-high-cpu --namespace AWS/EC2 --metric-name CPUUtilization --dimensions Name=InstanceId,Value=i-0abc123def4567890 --statistic Average --period 300 --evaluation-periods 2 --threshold 80 --comparison-operator GreaterThanThreshold --alarm-actions arn:aws:sns:eu-west-1:123456789012:alerts -
Test an alarm by setting its stateLinux, macOS, Windows
aws cloudwatch set-alarm-state --alarm-name web-1-high-cpu --state-value ALARM --state-reason "Testing"
Systems Manager #
-
Open a shell on an instance without SSH (needs the Session Manager plugin)Linux, macOS, Windows
aws ssm start-session --target i-0abc123def4567890 -
Forward a port from an instance to your machine (needs the Session Manager plugin)Linux, macOS, Windows
aws ssm start-session --target i-0abc123def4567890 --document-name AWS-StartPortForwardingSession --parameters portNumber=3389,localPortNumber=13389 -
Forward a port through an instance to a database behind it (needs the Session Manager plugin)Linux, macOS, Windows
aws ssm start-session --target i-0abc123def4567890 --document-name AWS-StartPortForwardingSessionToRemoteHost --parameters host=my-db.abc123xyz.eu-west-1.rds.amazonaws.com,portNumber=5432,localPortNumber=5432 -
List instances Systems Manager can reachLinux, macOS, Windows
aws ssm describe-instance-information --query "InstanceInformationList[].[InstanceId,PingStatus,PlatformName]" --output table -
Run a shell command on instancesLinux, macOS, Windows
aws ssm send-command --instance-ids i-0abc123def4567890 --document-name AWS-RunShellScript --parameters "commands=['uptime']" -
Get the output of a command you sentLinux, macOS, Windows
aws ssm get-command-invocation --command-id a1b2c3d4-5678-90ab-cdef-EXAMPLE11111 --instance-id i-0abc123def4567890 -
Read a parameterLinux, macOS, Windows
aws ssm get-parameter --name /app/prod/db-host --query Parameter.Value --output text -
Read an encrypted parameterLinux, macOS, Windows
aws ssm get-parameter --name /app/prod/db-host --with-decryption --query Parameter.Value --output textWarning: Prints the secret in plain text.
-
List the parameters under a pathLinux, macOS, Windows
aws ssm get-parameters-by-path --path /app/prod --recursive --query "Parameters[].Name" -
Save a parameterLinux, macOS, Windows
aws ssm put-parameter --name /app/prod/db-host --value "db.internal" --type String --overwrite -
Save an encrypted parameterLinux, macOS, Windows
aws ssm put-parameter --name /app/prod/db-host --value "MyPassword" --type SecureString --overwriteWarning: The value ends up in your shell history. Read it from a file with file:// to avoid that.
-
Delete a parameterLinux, macOS, Windows
aws ssm delete-parameter --name /app/prod/db-host
Secrets Manager and KMS #
-
List secretsLinux, macOS, Windows
aws secretsmanager list-secrets --query "SecretList[].Name" -
Read a secretLinux, macOS, Windows
aws secretsmanager get-secret-value --secret-id prod/db/password --query SecretString --output textWarning: Prints the secret in plain text.
-
Store a new secret from a fileLinux, macOS, Windows
aws secretsmanager create-secret --name prod/db/password --secret-string file://input.json -
Change a secret's valueLinux, macOS, Windows
aws secretsmanager put-secret-value --secret-id prod/db/password --secret-string file://input.json -
Rotate a secret nowLinux, macOS, Windows
aws secretsmanager rotate-secret --secret-id prod/db/password -
Delete a secret after 7 daysLinux, macOS, Windows
aws secretsmanager delete-secret --secret-id prod/db/password --recovery-window-in-days 7 -
Cancel a secret's deletionLinux, macOS, Windows
aws secretsmanager restore-secret --secret-id prod/db/password -
List KMS keys and their aliasesLinux, macOS, Windows
aws kms list-aliases --query "Aliases[].[AliasName,TargetKeyId]" --output table -
Encrypt a small file with a KMS keyLinux, macOS, Windows
aws kms encrypt --key-id alias/my-key --plaintext fileb://report.csv --query CiphertextBlob --output text > encrypted.b64 -
Turn on yearly rotation for a KMS keyLinux, macOS, Windows
aws kms enable-key-rotation --key-id 1234abcd-12ab-34cd-56ef-1234567890ab
Containers: ECR, ECS and EKS #
-
Sign Docker in to your ECR registryLinux, macOS, Windows
aws ecr get-login-password --region eu-west-1 | docker login --username AWS --password-stdin 123456789012.dkr.ecr.eu-west-1.amazonaws.com -
Make an ECR repositoryLinux, macOS, Windows
aws ecr create-repository --repository-name my-app --image-scanning-configuration scanOnPush=true -
List ECR repositoriesLinux, macOS, Windows
aws ecr describe-repositories --query "repositories[].repositoryUri" --output text -
List the images in a repositoryLinux, macOS, Windows
aws ecr describe-images --repository-name my-app --query "imageDetails[].[imageTags[0],imagePushedAt]" --output table -
Show an image's scan findingsLinux, macOS, Windows
aws ecr describe-image-scan-findings --repository-name my-app --image-id imageTag=latest -
Delete an imageLinux, macOS, Windows
aws ecr batch-delete-image --repository-name my-app --image-ids imageTag=latest -
List ECS clustersLinux, macOS, Windows
aws ecs list-clusters -
List the services in a clusterLinux, macOS, Windows
aws ecs list-services --cluster my-cluster -
Show a service's deployments and eventsLinux, macOS, Windows
aws ecs describe-services --cluster my-cluster --services web -
Redeploy a service, pulling the image againLinux, macOS, Windows
aws ecs update-service --cluster my-cluster --service web --force-new-deployment -
Change how many tasks a service runsLinux, macOS, Windows
aws ecs update-service --cluster my-cluster --service web --desired-count 10 -
Wait until a service has finished deployingLinux, macOS, Windows
aws ecs wait services-stable --cluster my-cluster --services web -
List the running tasks in a serviceLinux, macOS, Windows
aws ecs list-tasks --cluster my-cluster --service-name web -
Open a shell in a running container (needs the Session Manager plugin)Linux, macOS, Windows
aws ecs execute-command --cluster my-cluster --task 0123456789abcdef0123456789abcdef --container app --interactive --command "/bin/sh" -
List EKS clustersLinux, macOS, Windows
aws eks list-clusters -
Set up kubectl for an EKS clusterLinux, macOS, Windows
aws eks update-kubeconfig --name my-cluster --region eu-west-1 -
Show an EKS cluster's version and endpointLinux, macOS, Windows
aws eks describe-cluster --name my-cluster --query "cluster.[version,endpoint,status]" -
List an EKS cluster's node groupsLinux, macOS, Windows
aws eks list-nodegroups --cluster-name my-cluster
CloudFormation #
-
List stacksLinux, macOS, Windows
aws cloudformation list-stacks --stack-status-filter CREATE_COMPLETE UPDATE_COMPLETE --query "StackSummaries[].[StackName,StackStatus]" --output table -
Check a template for mistakesLinux, macOS, Windows
aws cloudformation validate-template --template-body file://template.yaml -
Create or update a stack from a templateLinux, macOS, Windows
aws cloudformation deploy --stack-name my-stack --template-file template.yaml -
Deploy a stack that makes IAM rolesLinux, macOS, Windows
aws cloudformation deploy --stack-name my-stack --template-file template.yaml --capabilities CAPABILITY_NAMED_IAM -
Deploy a stack with parameter valuesLinux, macOS, Windows
aws cloudformation deploy --stack-name my-stack --template-file template.yaml --parameter-overrides InstanceType=t3.small -
See what a deploy would change without doing itLinux, macOS, Windows
aws cloudformation deploy --stack-name my-stack --template-file template.yaml --no-execute-changeset -
Show a stack's outputsLinux, macOS, Windows
aws cloudformation describe-stacks --stack-name my-stack --query "Stacks[0].Outputs" --output table -
Show what went wrong in a stackLinux, macOS, Windows
aws cloudformation describe-stack-events --stack-name my-stack --query "StackEvents[?contains(ResourceStatus, 'FAILED')].[LogicalResourceId,ResourceStatusReason]" --output table -
List the resources in a stackLinux, macOS, Windows
aws cloudformation list-stack-resources --stack-name my-stack -
Check whether a stack has drifted from its templateLinux, macOS, Windows
aws cloudformation detect-stack-drift --stack-name my-stack -
Delete a stackLinux, macOS, Windows
aws cloudformation delete-stack --stack-name my-stackWarning: Deletes every resource the stack made, unless it's set to be kept.
-
Wait until a stack is deletedLinux, macOS, Windows
aws cloudformation wait stack-delete-complete --stack-name my-stack
Route 53 and CloudFront #
-
List hosted zonesLinux, macOS, Windows
aws route53 list-hosted-zones --query "HostedZones[].[Id,Name]" --output table -
List the records in a zoneLinux, macOS, Windows
aws route53 list-resource-record-sets --hosted-zone-id Z0123456789ABCDEFGHIJ --query "ResourceRecordSets[].[Name,Type,TTL]" --output table -
Add or change records from a JSON fileLinux, macOS, Windows
aws route53 change-resource-record-sets --hosted-zone-id Z0123456789ABCDEFGHIJ --change-batch file://input.json -
Check whether a record change has gone liveLinux, macOS, Windows
aws route53 get-change --id C0123456789ABCDEFGHIJ -
Test what a zone answers for a nameLinux, macOS, Windows
aws route53 test-dns-answer --hosted-zone-id Z0123456789ABCDEFGHIJ --record-name www.example.com --record-type A -
List CloudFront distributionsLinux, macOS, Windows
aws cloudfront list-distributions --query "DistributionList.Items[].[Id,DomainName,Aliases.Items[0]]" --output table -
Clear the whole CloudFront cacheLinux, macOS, Windows
aws cloudfront create-invalidation --distribution-id E1ABCDEFGHIJKL --paths "/*" -
Clear the cache for some pathsLinux, macOS, Windows
aws cloudfront create-invalidation --distribution-id E1ABCDEFGHIJKL --paths /index.html "/css/*" -
List SSL certificates in Certificate ManagerLinux, macOS, Windows
aws acm list-certificates --region us-east-1 --query "CertificateSummaryList[].[DomainName,Status]" --output table
RDS and DynamoDB #
-
List RDS databasesLinux, macOS, Windows
aws rds describe-db-instances --query "DBInstances[].[DBInstanceIdentifier,Engine,DBInstanceStatus,Endpoint.Address]" --output table -
Take a snapshot of a databaseLinux, macOS, Windows
aws rds create-db-snapshot --db-instance-identifier my-db --db-snapshot-identifier my-db-before-upgrade -
List a database's snapshotsLinux, macOS, Windows
aws rds describe-db-snapshots --db-instance-identifier my-db -
Stop a databaseLinux, macOS, Windows
aws rds stop-db-instance --db-instance-identifier my-dbWarning: AWS starts a stopped database again by itself after 7 days.
-
Start a databaseLinux, macOS, Windows
aws rds start-db-instance --db-instance-identifier my-db -
Reboot a databaseLinux, macOS, Windows
aws rds reboot-db-instance --db-instance-identifier my-db -
Get a short-lived password for IAM database sign-inLinux, macOS, Windows
aws rds generate-db-auth-token --hostname my-db.abc123xyz.eu-west-1.rds.amazonaws.com --port 5432 --username app_user --region eu-west-1 -
List DynamoDB tablesLinux, macOS, Windows
aws dynamodb list-tables -
Show a table's keys, size and settingsLinux, macOS, Windows
aws dynamodb describe-table --table-name my-table -
Get one item by its keyLinux, macOS, Windows
aws dynamodb get-item --table-name my-table --key file://input.json -
Read every item in a tableLinux, macOS, Windows
aws dynamodb scan --table-name my-tableWarning: Reads the whole table, which is slow and costs read capacity on big tables.
-
Count the items in a tableLinux, macOS, Windows
aws dynamodb scan --table-name my-table --select COUNT -
Turn on point-in-time recovery for a tableLinux, macOS, Windows
aws dynamodb update-continuous-backups --table-name my-table --point-in-time-recovery-specification PointInTimeRecoveryEnabled=true
SNS and SQS #
-
List SNS topicsLinux, macOS, Windows
aws sns list-topics -
Send a message to a topicLinux, macOS, Windows
aws sns publish --topic-arn arn:aws:sns:eu-west-1:123456789012:alerts --message "Hello from the CLI" -
Subscribe an email address to a topicLinux, macOS, Windows
aws sns subscribe --topic-arn arn:aws:sns:eu-west-1:123456789012:alerts --protocol email --notification-endpoint [email protected] -
List SQS queuesLinux, macOS, Windows
aws sqs list-queues -
Send a message to a queueLinux, macOS, Windows
aws sqs send-message --queue-url https://sqs.eu-west-1.amazonaws.com/123456789012/my-queue --message-body "Hello from the CLI" -
Read messages from a queueLinux, macOS, Windows
aws sqs receive-message --queue-url https://sqs.eu-west-1.amazonaws.com/123456789012/my-queue --max-number-of-messages 10 -
Show how many messages are waiting in a queueLinux, macOS, Windows
aws sqs get-queue-attributes --queue-url https://sqs.eu-west-1.amazonaws.com/123456789012/my-queue --attribute-names ApproximateNumberOfMessages -
Empty a queueLinux, macOS, Windows
aws sqs purge-queue --queue-url https://sqs.eu-west-1.amazonaws.com/123456789012/my-queueWarning: Deletes every message in the queue, with no undo.
Costs and audit #
-
Show this month's spend by serviceLinux, macOS, Windows
aws ce get-cost-and-usage --time-period Start=2026-11-01,End=2026-12-01 --granularity MONTHLY --metrics UnblendedCost --group-by Type=DIMENSION,Key=SERVICEWarning: Each Cost Explorer request is charged, at about 1 US cent.
-
Forecast this month's billLinux, macOS, Windows
aws ce get-cost-forecast --time-period Start=2026-11-01,End=2026-12-01 --granularity MONTHLY --metric UNBLENDED_COSTWarning: Each Cost Explorer request is charged, at about 1 US cent.
-
List your budgetsLinux, macOS, Windows
aws budgets describe-budgets --account-id 123456789012 -
Show who did what in the last 90 days (CloudTrail)Linux, macOS, Windows
aws cloudtrail lookup-events --max-results 20 -
Find who deleted somethingLinux, macOS, Windows
aws cloudtrail lookup-events --lookup-attributes AttributeKey=EventName,AttributeValue=DeleteBucket -
Find everything a user didLinux, macOS, Windows
aws cloudtrail lookup-events --lookup-attributes AttributeKey=Username,AttributeValue=alice -
List your CloudTrail trailsLinux, macOS, Windows
aws cloudtrail describe-trails -
List resources with a tag, across servicesLinux, macOS, Windows
aws resourcegroupstaggingapi get-resources --tag-filters Key=Environment,Values=prod --query "ResourceTagMappingList[].ResourceARN" -
Show a service's quotasLinux, macOS, Windows
aws service-quotas list-service-quotas --service-code ec2 --query "Quotas[].[QuotaName,Value]" --output table
Troubleshooting #
-
Show every request and response, to debug a commandLinux, macOS, Windows
aws s3 ls --debugWarning: The debug output can include signed request headers. Check it before you share it.
-
Check which credentials the CLI foundLinux, macOS, Windows
aws configure list -
Run a command without signing it, for public bucketsLinux, macOS, Windows
aws s3 ls s3://noaa-ghcn-pds --no-sign-request -
Send a command to a different endpoint, such as LocalStackLinux, macOS, Windows
aws s3 ls --endpoint-url http://localhost:4566 -
Give a slow command longer before it times outLinux, macOS, Windows
aws s3 cp report.csv s3://my-bucket/reports/2026.csv --cli-read-timeout 300 -
Retry throttled requests more timesLinux, macOS, Windows
aws configure set max_attempts 10 -
Show errors as JSON, for scriptsLinux, macOS, Windows
aws s3 ls s3://my-bucket --cli-error-format json -
Clear cached role credentialsLinux, macOS
rm -rf ~/.aws/cli/cache -
Clear cached SSO tokensLinux, macOS
rm -rf ~/.aws/sso/cacheWarning: You'll need to run aws sso login again.