Installation
Bash
# Linux (x86_64)
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
# Check version
aws --versionCredential Setup
Bash
# Interactive setup (Access Key, Secret, Region, output format)
aws configure
# Per-profile setup (multiple accounts)
aws configure --profile prod
aws configure --profile dev
# Temporary setup via environment variables
export AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
export AWS_DEFAULT_REGION=ap-northeast-2Credential file locations: ~/.aws/credentials, ~/.aws/config
EC2
Bash
# List instances (name, state, IP)
aws ec2 describe-instances \
--query 'Reservations[*].Instances[*].[Tags[?Key==`Name`].Value|[0],State.Name,PublicIpAddress]' \
--output table
# Start/stop instances
aws ec2 start-instances --instance-ids i-1234567890abcdef0
aws ec2 stop-instances --instance-ids i-1234567890abcdef0
# Add a security group rule (allow port 22 from my IP)
MY_IP=$(curl -s ifconfig.me)
aws ec2 authorize-security-group-ingress \
--group-id sg-12345678 \
--protocol tcp --port 22 --cidr "$MY_IP/32"S3
Bash
# List buckets
aws s3 ls
# Upload a file
aws s3 cp local-file.txt s3://my-bucket/path/
# Sync a directory
aws s3 sync ./dist s3://my-bucket/static --delete
# List objects in a bucket
aws s3 ls s3://my-bucket/ --recursive --human-readable
# Download a file
aws s3 cp s3://my-bucket/backup.tar.gz .
# Generate a presigned URL (valid for 24 hours)
aws s3 presign s3://my-bucket/private-file.pdf --expires-in 86400IAM
Bash
# Check current credentials
aws sts get-caller-identity
# List users
aws iam list-users --output table
# List roles
aws iam list-roles --query 'Roles[*].[RoleName,Arn]' --output tableUseful Options
Bash
# Use a specific profile
aws s3 ls --profile prod
# Output format (json/yaml/table/text)
aws ec2 describe-instances --output yaml
# Specify a region
aws ec2 describe-instances --region us-east-1
# Parse with jq
aws ec2 describe-instances | jq '.Reservations[].Instances[].PublicIpAddress'Editorial note
AI tools may assist drafting. Check the evidence in each guide for whether commands were run and which environment was used. Confirm the current docs for your version before applying instructions, and email us about errors. email us
Topic-related official docs (auto-linked · not per-claim sources)AWS documentation ↗
Questions & answers
Ask a question about this guide. We'll review and reply.