aws cli

AWS CLI v2

Quick reference for the AWS Command Line Interface: configure credentials, IAM identity, EC2 / Lambda / S3 / DynamoDB / IAM, profiles, SSO, and pagination / output formatting — with common options and practical examples.

40 commands

Help

aws --version

Print awscli version (v2.x).

aws --version
aws help

Top-level help — list service groups and basic usage.

aws help
aws <service> help

Show commands for one service.

<service> help; aws <service> <command> help

aws s3 help
aws <service> <command> help

Show every flag + parameter for a single API call.

aws ec2 run-instances help
aws <service> <command> --generate-cli-skeleton

Print a JSON skeleton with every required / optional field for a command — paste back as your input.

--generate-cli-skeleton <input|output>; --cli-input-json <file>; --cli-input-yaml <file>

aws ec2 run-instances --generate-cli-skeleton > ec2.json

Configure

aws configure

Interactive wizard — sets access key, secret, output format, region in `~/.aws/credentials` and `~/.aws/config`.

aws configure
aws configure --profile <name>

Same as `aws configure` but writes to a named profile.

--profile dev; --profile prod; --no-prompt

aws configure --profile prod
aws configure get <key>

Read a single value out of the active config.

default.region; default.output; <key>; --profile <name>

aws configure get region --profile prod
aws configure set <key> <value>

Set a single config value.

<key> <value>; --profile <name>

aws configure set region us-west-2
aws configure list

Show the active configuration (profile, region, access-key id, secret redacted).

aws configure list

SSO / Identity

aws sso login --profile <name>

Launch the SSO device-flow login (or browser redirect). Sets short-lived credentials for the profile.

--profile dev; --no-browser; --use-device-code

aws sso login --profile dev
aws sso configure

Configure an SSO profile interactively (start URL, region, account, role).

aws sso configure
aws sts get-caller-identity

Print the IAM principal (account / arn / user-id) for the active credentials — sanity-check after configuring.

--profile <name>; --no-verify-ssl; --endpoint-url <url>

aws sts get-caller-identity
aws sts assume-role --role-arn <arn> --role-session-name <name>

Switch to an IAM role, getting temporary credentials — useful for cross-account access.

--role-arn; --role-session-name; --external-id; --mfa-serial <arn>; --serial-number <arn>; --token-code <mfa>

aws sts assume-role --role-arn arn:aws:iam::123456789012:role/Admin --role-session-name admin

Output

aws <service> <command> --output <format>

Choose output format: `json` (default), `text`, `table`. Combine with `--query` for jq-like projection.

json; text; table; yaml; yaml-stream

aws ec2 describe-instances --output table
aws <service> <command> --query '<JMES>'

Project the response with a JMESPath expression (jq-like).

--query 'Reservations[].Instances[].InstanceId'; --query 'Reservations[].Instances[].[InstanceId,State.Name]'

aws ec2 describe-instances --query 'Reservations[].Instances[].[InstanceId,State.Name]' --output table
aws <service> <command> --no-paginate

Disable auto-pagination — return the first page only (faster; useful when you only want a count).

aws s3 ls --no-paginate
aws <service> <command> --cli-binary-format raw-in-base64-out

Read input parameters as base64 — needed for binary params like `--zip-file fileb://lambda.zip`.

raw-in-base64-out; base64

aws lambda update-function-code --function-name fn --zip-file fileb://out.zip --cli-binary-format raw-in-base64-out

EC2

aws ec2 describe-instances

List every EC2 instance with full detail.

--instance-ids i-xxx; --filters Name=tag:Name,Values=prod; --query; --output

aws ec2 describe-instances --query 'Reservations[].Instances[].{ID:InstanceId,State:State.Name}' --output table
aws ec2 start-instances --instance-ids <id>

Start one or more stopped instances.

--instance-ids i-xxx i-yyy

aws ec2 start-instances --instance-ids i-0abc123
aws ec2 stop-instances --instance-ids <id>

Stop one or more running instances (without terminating).

aws ec2 stop-instances --instance-ids i-0abc123
aws ec2 create-key-pair --key-name <name> --query 'KeyMaterial' --output text > key.pem

Create a new SSH key pair and save the private key to a `.pem` file with the right permissions.

aws ec2 create-key-pair --key-name dev --query 'KeyMaterial' --output text > dev.pem && chmod 400 dev.pem

S3

aws s3 ls

List buckets (without args) or files under a prefix.

s3://<bucket>/<prefix>; --recursive; --human-readable; --summarize

aws s3 ls s3://my-bucket/data/
aws s3 cp <local> s3://<bucket>/<key>

Upload or copy a file. `s3://...` can be source or destination.

--recursive; --exclude '*'; --include '*.log'; --storage-class STANDARD|GLACIER|...; --acl public-read

aws s3 cp ./build/ s3://my-bucket/release/ --recursive
aws s3 sync <src> s3://<bucket>/<dst>

Two-way S3 directory sync (uploads new / changed files, deletes destination-side extras unless `--delete` is passed).

--delete; --exclude; --include; --no-progress; --exact-timestamps

aws s3 sync ./dist s3://my-bucket/app/ --delete
aws s3 mb s3://<bucket>

Make a new S3 bucket. Region defaults to us-east-1; pass `--region` to override.

--region eu-west-1

aws s3 mb s3://my-new-bucket --region eu-west-1
aws s3 rb s3://<bucket>

Remove bucket (use `--force` to wipe objects first).

--force; --no-progress

aws s3 rb s3://old-bucket --force
aws s3 presign s3://<bucket>/<key> --expires-in <seconds>

Generate a presigned URL that expires after `<seconds>` — useful for sharing private files.

aws s3 presign s3://my-bucket/file.pdf --expires-in 3600

Lambda

aws lambda list-functions

List every Lambda function in the current region.

--function-version ALL; --max-items 50; --query 'Functions[].FunctionName'

aws lambda list-functions --query 'Functions[].FunctionName' --output text
aws lambda update-function-code --function-name <name> --zip-file fileb://fn.zip

Update a function's code from a local zip. Use `--cli-binary-format raw-in-base64-out` on some setups.

aws lambda update-function-code --function-name my-fn --zip-file fileb://out.zip --cli-binary-format raw-in-base64-out
aws lambda invoke --function-name <name> --payload '{}' out.json

Invoke a function synchronously — write the response to `out.json`.

--invocation-type Event|RequestResponse|DryRun; --log-type Tail; --cli-binary-format

aws lambda invoke --function-name my-fn --payload '{"key":"value"}' out.json && cat out.json

DynamoDB

aws dynamodb scan --table-name <name>

Scan a DynamoDB table — reads every item (use `query` with a key condition when possible).

--table-name; --filter-expression; --projection-expression; --select; --max-items

aws dynamodb scan --table-name users --max-items 5
aws dynamodb query --table-name <name> --key-condition-expression 'pk = :v' --expression-attribute-values '{":v":{"S":"u1"}}'

Query items by partition key with a key condition expression.

aws dynamodb query --table-name users --key-condition-expression '#u = :u' --expression-attribute-names '{"#u":"userId"}' --expression-attribute-values '{":u":{"S":"u1"}}'

IAM

aws iam list-users

List every IAM user in the account.

--path-prefix /; --max-items

aws iam list-users --query 'Users[].UserName' --output text
aws iam create-user --user-name <name>

Create a new IAM user.

aws iam create-user --user-name new-dev
aws iam attach-user-policy --user-name <name> --policy-arn <arn>

Attach a managed policy to a user.

aws iam attach-user-policy --user-name new-dev --policy-arn arn:aws:iam::aws:policy/ReadOnlyAccess

Profiles

aws --profile <name> <service> <cmd>

Run any command under a named profile (must already be configured).

--profile prod; --profile dev; --profile staging

aws --profile prod s3 ls
AWS_PROFILE=<name> aws <service> <cmd>

Set the profile via environment variable — useful in scripts.

AWS_PROFILE=prod aws lambda list-functions

Diagnose

aws --debug <service> <cmd>

Dump HTTP wire-level logs to stderr — useful when diagnosing signing or payload errors.

--debug; --no-verify-ssl; --ca-bundle <file>; --cli-read-timeout <seconds>

aws --debug s3 ls 2> aws.log
aws --no-sign-request <service> <cmd>

Make unsigned requests — useful against public buckets / test endpoints.

aws --no-sign-request s3 cp public.txt s3://public-bucket/x

Related command cheatsheets

About AWS CLI

The AWS Command Line Interface (awscli) is Amazon's official tool for controlling AWS services from a terminal. The current line is AWS CLI v2 (released 2020; awscli 1.x is in maintenance). v2 ships as a single installer (msi / pkg / signed zip), supports SSO, the new `aws sso login` flow, automatic pagination, and binary parameters (handles base64-encoded blobs like Lambda zip uploads). Configuration is split into `~/.aws/config` (region, output format) and `~/.aws/credentials` (access keys), but with IAM Identity Center / SSO you typically use `aws sso configure` instead of long-lived keys. Every AWS service is reachable via `aws <service> <command>` — `aws ec2 describe-instances`, `aws s3 sync`, `aws lambda invoke`, `aws dynamodb scan`. The CLI is Apache-2.0 licensed. The newer alternative is `aws-shell` (interactive completion) and the AWS CDK (`cdk`) for infrastructure-as-code. AWS CLI v2 does not upload your source code anywhere except the API calls you explicitly make.

Cheatsheet version 1.0.0