Snippets

aws-cli

10 aws-cli code snippets across 1 language. Copy-paste solutions from production code.

10

aws cli

10 snippets

Assume an IAM Role from the AWS CLI

Use aws sts assume-role to swap into a cross-account IAM role and export temporary credentials into your shell session.

aws-cliiamsts+2
INTERMEDIATEMay 30, 2026

aws ecr get-login-password: Docker Login to ECR

Use aws ecr get-login-password piped to docker login to authenticate with a private Amazon ECR registry. Cross-region included.

aws-cliecrdocker+2
BEGINNERJun 7, 2026

Debug Which AWS Identity You Are Using

Use aws sts get-caller-identity to see which AWS account, IAM user, and role your CLI is currently authenticated as.

aws-cliiamsts+2
BEGINNERApr 20, 2026

Fetch and Parse a Secret from AWS Secrets Manager

Use aws secretsmanager get-secret-value with jq to fetch a JSON secret and pipe individual fields into shell variables.

aws-clisecrets-managerjq+2
BEGINNERMay 20, 2026

Fetch Monthly AWS Spend by Service from the CLI

Use aws ce get-cost-and-usage to pull a monthly cost breakdown grouped by service. Cleaner than navigating Cost Explorer in the console.

aws-clicost-explorerbilling+2
INTERMEDIATEJun 23, 2026

Generate a Presigned URL for an S3 Object

Use aws s3 presign to generate a time-limited download URL for a private S3 object. Share files without making the bucket public.

aws-clis3presigned-url+2
BEGINNERApr 28, 2026

Invoke a Lambda Synchronously and Read the Response

Use aws lambda invoke with a payload, decode base64 logs, and pretty-print the response with jq. Full debug loop in one command.

aws-clilambdainvoke+2
BEGINNERJun 15, 2026

List Running EC2 Instances as a Clean Table

Use aws ec2 describe-instances with a JMESPath query to print every running instance with ID, IP, instance type, and Name tag.

aws-cliec2describe-instances+2
BEGINNERJun 25, 2026

Sync a Folder to S3 with Include and Exclude Filters

Use aws s3 sync with --exclude, --include, --dryrun, and --delete to deploy a directory to an S3 bucket safely.

aws-clis3sync+2
BEGINNERApr 8, 2026

Tail CloudWatch Logs Live with the AWS CLI

Use aws logs tail with --follow to stream a CloudWatch log group in real time. Filter, time-range, and color the output.

aws-clicloudwatchlogs+2
BEGINNERMay 10, 2026