aws cli cheatsheet
EC2 (Elastic Compute Cloud)
Instances
aws ec2 describe-instances
aws ec2 start-instances --instance-ids <instance-id>
aws ec2 stop-instances --instance-ids <instance-id>
aws ec2 reboot-instances --instance-ids <instance-id>
aws ec2 terminate-instances --instance-ids <instance-id>
Key Pairs
aws ec2 describe-key-pairs
aws ec2 create-key-pair --key-name <key-name>
Security Groups
aws ec2 describe-security-groups
aws ec2 create-security-group --group-name <group-name> --description "<description>"
S3 (Simple Storage Service)
Buckets
aws s3 mb s3://<bucket-name>
aws s3 rb s3://<bucket-name> --force
Objects
- List objects in a bucket:
aws s3 ls s3://<bucket-name>/
aws s3 cp <local-file> s3://<bucket-name>/
aws s3 cp s3://<bucket-name>/<file-name> <local-path>
- Sync local directory with S3 bucket:
aws s3 sync <local-dir> s3://<bucket-name>
aws s3 rm s3://<bucket-name>/<file-name>
RDS (Relational Database Service)
Instances
aws rds describe-db-instances
aws rds start-db-instance --db-instance-identifier <db-instance-id>
aws rds stop-db-instance --db-instance-identifier <db-instance-id>
aws rds delete-db-instance --db-instance-identifier <db-instance-id> --skip-final-snapshot
Snapshots
aws rds describe-db-snapshots
aws rds create-db-snapshot --db-instance-identifier <db-instance-id> --db-snapshot-identifier <snapshot-name>
ECR (Elastic Container Registry)
Repositories
aws ecr describe-repositories
aws ecr create-repository --repository-name <repository-name>
aws ecr delete-repository --repository-name <repository-name> --force
Images
- List images in a repository:
aws ecr list-images --repository-name <repository-name>
- Authenticate Docker with ECR:
aws ecr get-login-password --region <region> | docker login --username AWS --password-stdin <account-id>.dkr.ecr.<region>.amazonaws.com
docker push <account-id>.dkr.ecr.<region>.amazonaws.com/<repository-name>:<tag>
IAM (Identity and Access Management)
Users
aws iam create-user --user-name <user-name>
aws iam delete-user --user-name <user-name>
Roles
aws iam create-role --role-name <role-name> --assume-role-policy-document file://<policy-file>.json
aws iam delete-role --role-name <role-name>
Policies
- Attach a policy to a user:
aws iam attach-user-policy --user-name <user-name> --policy-arn <policy-arn>
Credentials
- Configure CLI with credentials:
Profile Management
aws <service> <command> --profile <profile-name>
- Set environment variables for credentials:
export AWS_ACCESS_KEY_ID=<your-access-key>
export AWS_SECRET_ACCESS_KEY=<your-secret-key>
export AWS_DEFAULT_REGION=<your-region>
Rotate Access Keys
aws iam list-access-keys --user-name <user-name>
aws iam create-access-key --user-name <user-name>
aws iam delete-access-key --access-key-id <access-key-id> --user-name <user-name>