Skip to content

AWS CLI Cheatsheet for Developers

Scope: EC2 and S3 Only, with Useful Flags and grep Examples


Setup

Configure your credentials (run once):

aws configure

Profiles (Multiple AWS Accounts)

  • List configured profiles:

    aws configure list-profiles
    
  • Use a specific profile for a command:

    aws s3 ls --profile myprofile
    aws ec2 describe-instances --profile myprofile
    
  • Set or update a specific profile:

    aws configure --profile myprofile
    

Amazon EC2

1. List Instances (with output filtering)

aws ec2 describe-instances
# Filter by state:
aws ec2 describe-instances --filters Name=instance-state-name,Values=running
# Filter by tag value:
aws ec2 describe-instances --filters Name=tag:Name,Values="MyServer"
# Show only Instance IDs using jq:
aws ec2 describe-instances | jq -r '.Reservations[].Instances[].InstanceId'
# Using grep to find running instances:
aws ec2 describe-instances | grep "InstanceId"

2. Start/Stop Multiple Instances at Once

aws ec2 start-instances --instance-ids i-12345678 i-87654321
aws ec2 stop-instances --instance-ids $(cat ids.txt)

3. List Public IPs of Running Instances (using grep/jq)

aws ec2 describe-instances --filters Name=instance-state-name,Values=running \\
  | grep PublicIpAddress
# or with jq for just IPs:
aws ec2 describe-instances --filters Name=instance-state-name,Values=running \\
  | jq -r '.Reservations[].Instances[].PublicIpAddress'

Amazon S3

1. List Buckets

aws s3 ls

2. List All Files in a Bucket (including subfolders)

aws s3 ls s3://my-bucket/ --recursive

3. Upload Local Directory to Bucket (Recursive)

aws s3 cp ./data/ s3://my-bucket/data/ --recursive

4. Download All Files from a Bucket (Recursive)

aws s3 cp s3://my-bucket/data/ ./data/ --recursive

5. Sync Local Directory/Bucket (Upload/Download only changed/added files)

aws s3 sync ./mydir s3://my-bucket/mydir
aws s3 sync s3://my-bucket/mydir ./mydir

6. Remove All Files in a Bucket (Recursive)

aws s3 rm s3://my-bucket/path/ --recursive

7. Find Files in a Bucket with grep

aws s3 ls s3://my-bucket/path/ --recursive | grep "2026"
aws s3 ls s3://my-bucket/path/ --recursive | grep "\\.csv$"

8. Find Objects Larger Than 1GB (using awk for size)

aws s3 ls s3://my-bucket/ --recursive | awk '$4 > 1073741824'

Miscellaneous

Output Formatting

aws ec2 describe-instances --output table

Useful Help

aws ec2 help
aws s3 help

Tips:

  • Use -profile <profilename> for multiple AWS credentials (see "Profiles" section).
  • Combine with Unix commands (grep, awk, sort, jq) for advanced filtering and formatting.