AWS CLI Quick Reference Cheat Sheet

Quick reference guide for AWS CLI: S3 sync/copy, EC2 management, Lambda invoke, IAM policies, and CloudWatch.

Containers & Cloud
aws
aws-cli
cloud

The AWS Command Line Interface (AWS CLI) is a unified tool to manage your Amazon Web Services resources from the command line.

Configuration & Credentials

Table
CommandAction / Purpose
aws configureInteractively configure Access Key, Secret Key, region, and format
aws configure listDisplay currently active credentials and configuration source
aws sts get-caller-identityPrint authenticated IAM principal identity (Account, UserId, ARN)

Amazon S3 Operations

bash
# List all S3 buckets in account
aws s3 ls

# List contents of specific bucket
aws s3 ls s3://my-app-bucket/prefix/

# Sync local directory to S3 bucket (delete remote extra files)
aws s3 sync ./dist s3://my-app-bucket/ --delete

# Copy file with explicit Content-Type header
aws s3 cp image.png s3://my-app-bucket/assets/image.png --content-type "image/png"

# Remove non-empty bucket recursively
aws s3 rb s3://my-app-bucket/ --force

Amazon EC2 Management

bash
# Describe running instances with output filter
aws ec2 describe-instances \
  --filters "Name=instance-state-name,Values=running" \
  --query "Reservations[*].Instances[*].[InstanceId,PublicIpAddress,Tags[?Key=='Name'].Value|[0]]" \
  --output table

# Start / Stop EC2 instance
aws ec2 start-instances --instance-ids i-0123456789abcdef0
aws ec2 stop-instances --instance-ids i-0123456789abcdef0

AWS Lambda & CloudWatch Logs

Table
ActionCommand Example
Invoke Lambda Functionaws lambda invoke --function-name my-func --cli-binary-format raw-in-base64-out --payload '{"key":"val"}' out.json
Tail CloudWatch Log Streamaws logs tail /aws/lambda/my-func --follow --format short
Get SSM Parameter Valueaws ssm get-parameter --name "/app/prod/db_pass" --with-decryption

Common Pitfalls & Tips

[!WARNING] In AWS CLI v2, binary payloads for aws lambda invoke must be base64-encoded or called with --cli-binary-format raw-in-base64-out.

[!TIP] Use --query with JMESPath expressions and --output json|table|text to extract precise fields directly from AWS CLI responses.