Skip to main content

AWS CLI Cheatsheet

By Dejan Panovski Updated on Download PDF

Quick reference for AWS CLI commands, profiles, and output filtering

The AWS CLI puts every AWS API behind a single aws command, so you can manage instances, buckets, secrets, and logs from your shell. This cheatsheet covers AWS CLI version 2 syntax for authentication, profiles, output filtering, and the services Linux administrators reach for most.

Installation and Setup

Install AWS CLI version 2 and set the basic configuration. Full walkthrough in installing and configuring the AWS CLI on Linux .

CommandDescription
curl https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip -o awscliv2.zipDownload the x86_64 installer
curl https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip -o awscliv2.zipDownload the ARM64 installer
unzip awscliv2.zipExtract the installer
sudo ./aws/installInstall AWS CLI version 2
sudo ./aws/install --updateUpdate from a freshly extracted installer
aws --versionShow the installed version
aws configureInteractive credential and region setup
aws configure listShow active settings and where they come from
aws configure get regionRead a single config value
aws configure set region eu-central-1Write a single config value
complete -C aws_completer awsEnable Bash command completion
aws ec2 helpOpen the reference for a service

Profiles and Authentication

Static access keys configured with aws configure live in ~/.aws/credentials, while other settings live in ~/.aws/config. Prefer temporary credentials from aws login or IAM Identity Center.

CommandDescription
aws loginSign in with AWS console credentials
aws login --profile devSign in to a named profile
aws login --remoteSign in from a host without a browser
aws logout --profile devClear cached login credentials for a profile
aws configure --profile devConfigure a profile with an access key
aws s3 ls --profile devRun one command as a profile
export AWS_PROFILE=devUse a profile for the whole shell
aws configure list-profilesList configured profiles
aws configure ssoSet up an IAM Identity Center profile
aws sso login --profile devStart or refresh an SSO session
aws sso logoutClear cached SSO credentials
aws sts get-caller-identityShow the account and identity in use
aws sts assume-role --role-arn arn --role-session-name cliGet temporary role credentials
export AWS_REGION=eu-west-1Override the region for the shell

Common Options

Frequently used options. Availability depends on the service and operation.

OptionDescription
--region eu-west-1Target a specific region
--profile devUse a named profile
--output jsonSet the response format
--no-cli-pagerPrint output instead of opening a pager
--dry-runCheck permissions without acting on supported EC2 operations
--cli-auto-promptPrompt for parameters interactively
--no-paginateReturn only the first page from a paginated operation
--page-size 100Set the API page size for a paginated operation
--max-items 20Limit output from a paginated operation
--cli-input-json file://params.jsonRead parameters for a modeled API operation
--generate-cli-skeletonPrint a parameter template for a modeled API operation
--debugPrint the full request and response trace

Output Formatting and Queries

The --query option uses JMESPath and runs client side. Service-specific options such as --filters run server side, which can reduce response size and improve response time for large data sets. Pipe --output json into jq when a query gets hard to read.

CommandDescription
aws s3api list-buckets --output tableHuman-readable table
aws s3api list-buckets --output textTab-delimited text
aws s3api list-buckets --output yamlYAML response
aws s3api list-buckets --query "Buckets[].Name"Return one field
aws ec2 describe-instances --query "Reservations[].Instances[].[InstanceId,State.Name]" --output textReturn several fields as columns
aws ec2 describe-instances --query "Reservations[].Instances[?State.Name=='running'].InstanceId"Filter results client side
aws ec2 describe-instances --filters Name=instance-state-name,Values=runningFilter results server side
aws ec2 describe-volumes --query "Volumes[0:5]"Slice the result list
aws ec2 wait instance-running --instance-ids i-0abc123Block until a state is reached

S3 Buckets and Objects

Everyday transfers with the high-level aws s3 commands. More examples in aws s3 commands .

CommandDescription
aws s3 lsList all buckets
aws s3 ls s3://bucket --recursive --summarizeList objects with a size total
aws s3 cp file.txt s3://bucket/Upload a file
aws s3 cp s3://bucket/file.txt .Download a file
aws s3 cp ./dir s3://bucket/dir --recursiveUpload a directory
aws s3 sync ./dir s3://bucket/dirCopy only new and changed files
aws s3 sync ./dir s3://bucket/dir --delete --dryrunPreview a mirror that removes stale files
aws s3 rm s3://bucket/dir/ --recursive --dryrunPreview a recursive delete
aws s3 mb s3://bucketCreate a bucket
aws s3 rb s3://bucketRemove an empty bucket
aws s3 presign s3://bucket/file.txt --expires-in 3600Generate a temporary download link

EC2 Instances

Launch, inspect, and control instances.

CommandDescription
aws ec2 describe-instancesList instances and their details
aws ec2 describe-instances --instance-ids i-0abc123Details for one instance
aws ec2 describe-instance-statusHealth and scheduled events
aws ec2 run-instances --image-id ami-0abc --instance-type t3.micro --key-name mykeyLaunch an instance
aws ec2 start-instances --instance-ids i-0abc123Start a stopped instance
aws ec2 stop-instances --instance-ids i-0abc123Stop an instance
aws ec2 reboot-instances --instance-ids i-0abc123Reboot an instance
aws ec2 terminate-instances --instance-ids i-0abc123Permanently terminate an instance
aws ec2 create-tags --resources i-0abc123 --tags Key=Name,Value=webTag a resource
aws ec2 describe-images --owners 099720109477 --filters "Name=name,Values=ubuntu/images/hvm-ssd-gp3/ubuntu-noble-24.04-amd64-server-*"Find official Ubuntu 24.04 AMIs
aws ec2 get-console-output --instance-id i-0abc123Read the instance console log

Security Groups and Key Pairs

Network access and SSH keys for EC2. Private key files are unencrypted, so keep them readable only by your user.

CommandDescription
aws ec2 describe-security-groupsList security groups
aws ec2 create-security-group --group-name web --description "Web tier"Create a security group
aws ec2 authorize-security-group-ingress --group-id sg-0abc --protocol tcp --port 22 --cidr 203.0.113.10/32Allow inbound traffic
aws ec2 revoke-security-group-ingress --group-id sg-0abc --protocol tcp --port 22 --cidr 203.0.113.10/32Remove an inbound rule
aws ec2 delete-security-group --group-id sg-0abcDelete a security group
aws ec2 create-key-pair --key-name mykey --query KeyMaterial --output text > mykey.pemCreate a key pair and save the private key
chmod 400 mykey.pemRestrict private key permissions
aws ec2 describe-key-pairsList key pairs
aws ec2 delete-key-pair --key-name mykeyDelete a key pair
aws ec2 describe-vpcsList VPCs
aws ec2 describe-subnets --filters Name=vpc-id,Values=vpc-0abcList subnets in a VPC
aws ec2 allocate-addressReserve an elastic IP
aws ec2 associate-address --instance-id i-0abc123 --allocation-id eipalloc-0abcAttach an elastic IP

EBS Volumes and Snapshots

Block storage and backups.

CommandDescription
aws ec2 describe-volumesList volumes
aws ec2 create-volume --size 20 --availability-zone eu-central-1aCreate a volume
aws ec2 attach-volume --volume-id vol-0abc --instance-id i-0abc123 --device /dev/sdfAttach a volume
aws ec2 detach-volume --volume-id vol-0abcDetach a volume
aws ec2 delete-volume --volume-id vol-0abcPermanently delete a volume
aws ec2 create-snapshot --volume-id vol-0abc --description "nightly"Snapshot a volume
aws ec2 describe-snapshots --owner-ids selfList your snapshots
aws ec2 copy-snapshot --region eu-west-1 --source-region eu-central-1 --source-snapshot-id snap-0abcCopy a snapshot from eu-central-1 to eu-west-1
aws ec2 delete-snapshot --snapshot-id snap-0abcPermanently delete a snapshot

IAM Users and Roles

Identities, policies, and access keys. Creating an access key prints its secret once, so store it securely and never commit it to version control.

CommandDescription
aws iam list-usersList IAM users
aws iam create-user --user-name devCreate a user
aws iam delete-user --user-name devPermanently delete a user after removing dependencies
aws iam list-rolesList roles
aws iam get-role --role-name deployShow a role and its trust policy
aws iam attach-user-policy --user-name dev --policy-arn arn:aws:iam::aws:policy/ReadOnlyAccessAttach a managed policy
aws iam list-attached-user-policies --user-name devList policies attached to a user
aws iam create-access-key --user-name devCreate an access key
aws iam list-access-keys --user-name devList access keys and creation dates
aws iam update-access-key --user-name dev --access-key-id AKIA123 --status InactiveDisable a key before deleting it
aws iam delete-access-key --user-name dev --access-key-id AKIA123Permanently delete an access key
aws iam get-account-summaryAccount-wide IAM counts and limits

Systems Manager and Secrets

Shell access without SSH, plus configuration and secret storage. The start-session command needs the Session Manager plugin installed locally. Pass secret values from protected files so they do not enter shell history, and keep decrypted output out of shared logs.

CommandDescription
aws ssm start-session --target i-0abc123Open a shell on an instance
aws ssm describe-instance-informationList instances managed by SSM
aws ssm send-command --instance-ids i-0abc123 --document-name AWS-RunShellScript --parameters commands="uptime"Run a command on an instance
aws ssm get-command-invocation --command-id 1a2b --instance-id i-0abc123Read the output of a sent command
aws ssm put-parameter --name /app/db_url --value file://db-url.txt --type SecureStringStore an encrypted parameter from a file
aws ssm get-parameter --name /app/db_url --with-decryptionRead and decrypt a parameter
aws ssm get-parameters-by-path --path /app --recursiveList parameters under a path
aws secretsmanager list-secretsList secrets
aws secretsmanager get-secret-value --secret-id prod/db --query SecretString --output textPrint a decrypted secret value
aws secretsmanager create-secret --name prod/db --secret-string file://secret.jsonCreate a secret from a file

CloudWatch Logs and Alarms

Read application and service logs from the terminal.

CommandDescription
aws logs describe-log-groupsList log groups
aws logs describe-log-streams --log-group-name /aws/lambda/fnList streams in a group
aws logs tail /aws/lambda/fn --followStream new log events live
aws logs tail /aws/lambda/fn --since 1h --format shortShow the last hour of logs
aws logs filter-log-events --log-group-name /aws/lambda/fn --filter-pattern ERRORSearch log events
aws logs create-log-group --log-group-name /app/webCreate a log group
aws logs put-retention-policy --log-group-name /app/web --retention-in-days 30Set log retention
aws logs delete-log-group --log-group-name /app/webPermanently delete a log group and its logs
aws cloudwatch describe-alarmsList alarms and their state
aws cloudwatch describe-alarms --state-value ALARMShow only firing alarms

Lambda Functions

Deploy and invoke functions. AWS CLI version 2 expects base64 input for blob parameters by default, so literal JSON passed to --payload needs --cli-binary-format raw-in-base64-out.

CommandDescription
aws lambda list-functionsList functions
aws lambda get-function --function-name fnShow configuration and code location
aws lambda invoke --function-name fn out.jsonInvoke a function
aws lambda invoke --function-name fn --cli-binary-format raw-in-base64-out --payload '{"key":"value"}' out.jsonInvoke with a JSON payload
aws lambda update-function-code --function-name fn --zip-file fileb://fn.zipDeploy new code
aws lambda update-function-configuration --function-name fn --timeout 30Change a setting
aws lambda publish-version --function-name fnPublish an immutable version
aws lambda list-versions-by-function --function-name fnList published versions
aws lambda delete-function --function-name fnPermanently delete a function

ECR Container Images

Authenticate Docker against a registry with aws ecr get-login-password --region eu-central-1 piped into docker login --username AWS --password-stdin 123456789012.dkr.ecr.eu-central-1.amazonaws.com. Container commands are in the Docker cheatsheet .

CommandDescription
aws ecr get-login-password --region eu-central-1Print a registry password for Docker
aws ecr describe-repositoriesList repositories
aws ecr create-repository --repository-name appCreate a repository
aws ecr list-images --repository-name appList image tags and digests
aws ecr describe-images --repository-name appShow image size and push date
aws ecr batch-delete-image --repository-name app --image-ids imageTag=oldDelete an image
aws ecr delete-repository --repository-name app --forcePermanently delete a repository and its images