Snippets / Tags
aws-cli
10 aws-cli code snippets across 1 language. Copy-paste solutions from production code.
10
snippets
aws cli
10 snippetsAssume 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 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.
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.
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.
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.
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.
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.
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.
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.
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.