DevOps & Cloud57 entries

AWS CLI

S3, EC2, IAM, Lambda, ECS, CloudFormation, and essential AWS CLI commands

1Configuration & Identity

aws configure
Set up access key, secret, region, output
aws configure list
Show current configuration values
aws sts get-caller-identity
Show current IAM user/role
aws configure set region us-east-1
Set default region
aws configure --profile staging
Set up named profile
export AWS_PROFILE=staging
Switch to named profile
aws configure list-profiles
List all configured profiles

2S3 (Storage)

aws s3 ls
List all S3 buckets
aws s3 ls s3://bucket-name/
List objects in a bucket
aws s3 cp file.txt s3://bucket/path/
Upload file to S3
aws s3 cp s3://bucket/file.txt ./
Download file from S3
aws s3 sync ./dir s3://bucket/prefix/
Sync local directory to S3
aws s3 rm s3://bucket/file.txt
Delete file from S3
aws s3 rm s3://bucket/ --recursive
Delete all objects in bucket
aws s3 mb s3://new-bucket
Create a new S3 bucket
aws s3 rb s3://bucket --force
Delete bucket and all contents
aws s3 presign s3://bucket/file --expires-in 3600
Generate presigned URL (1 hour)

3EC2 (Compute)

aws ec2 describe-instances
List all EC2 instances
aws ec2 describe-instances --filters "Name=tag:Name,Values=web"
Filter instances by tag
aws ec2 start-instances --instance-ids i-xxx
Start an EC2 instance
aws ec2 stop-instances --instance-ids i-xxx
Stop an EC2 instance
aws ec2 terminate-instances --instance-ids i-xxx
Terminate an EC2 instance
aws ec2 describe-security-groups
List security groups
aws ec2 describe-vpcs
List VPCs
aws ec2 describe-subnets
List subnets

4IAM (Identity)

aws iam list-users
List all IAM users
aws iam list-roles
List all IAM roles
aws iam list-policies --scope Local
List custom IAM policies
aws iam get-user --user-name dev
Show user details
aws iam create-user --user-name dev
Create a new IAM user
aws iam attach-user-policy --user-name dev --policy-arn <arn>
Attach policy to user
aws iam create-access-key --user-name dev
Generate access key for user

5Lambda (Serverless)

aws lambda list-functions
List all Lambda functions
aws lambda invoke --function-name fn out.json
Invoke a Lambda function
aws lambda get-function --function-name fn
Show function configuration
aws lambda update-function-code --function-name fn --zip-file fileb://code.zip
Deploy new function code
aws lambda list-event-source-mappings
List event source triggers
aws logs tail /aws/lambda/fn --follow
Tail Lambda CloudWatch logs

6ECS & ECR (Containers)

aws ecr get-login-password | docker login --username AWS --password-stdin <acct>.dkr.ecr.<region>.amazonaws.com
Login to ECR registry
aws ecr describe-repositories
List ECR repositories
aws ecs list-clusters
List ECS clusters
aws ecs list-services --cluster my-cluster
List services in cluster
aws ecs describe-services --cluster my-cluster --services my-svc
Show service details
aws ecs update-service --cluster my-cluster --service my-svc --force-new-deployment
Force new deployment

7CloudFormation & SSM

aws cloudformation list-stacks --stack-status-filter CREATE_COMPLETE
List active stacks
aws cloudformation deploy --template-file tpl.yaml --stack-name my-stack
Deploy/update a stack
aws cloudformation describe-stack-events --stack-name my-stack
Show stack events
aws cloudformation delete-stack --stack-name my-stack
Delete a stack
aws ssm get-parameter --name /app/db-password --with-decryption
Get SSM parameter value
aws ssm put-parameter --name /app/key --value "val" --type SecureString
Store encrypted parameter

8Common Flags & Output

--region us-west-2
Override default region
--output json
Output as JSON (default)
--output table
Output as formatted table
--output text
Output as tab-separated text
--query "Reservations[].Instances[].InstanceId"
JMESPath query to filter output
--no-paginate
Disable automatic pagination
--dry-run
Check permissions without executing