AWS CLI

AWS CLI

Cloud Watch

List logs in the last 30 minutes sorted desc by timestamp and return the last 10 messages

1
aws logs filter-log-events --log-group-name example-app --start-time $(( $(date '+%s') * 1000 - 1800000)) --query 'reverse(sort_by(events, &timestamp))[*]' | jq '.[:10][].message'

EC2

List AMIs owned by Amazon

1
aws ec2 describe-images --owners self amazon

List latest Ubuntu 20.04 amd64 AMIs

1
aws ec2 describe-images --owners 099720109477 --filters "Name=name,Values=ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server*" --query 'sort_by(Images,&CreationDate)[-1].ImageId'

ELBv2 / ALB / NLB

List load balancer ARNs

1
aws elbv2 describe-load-balancers --query 'LoadBalancers[].[LoadBalancerArn]' --output text

List listener ARNs on load balancer

1
 aws elbv2 describe-listeners --query 'Listeners[].[ListenerArn]' --output text --load-balancer-arn <ARN>

Describe listener rules

1
aws elbv2 describe-rules --listener-arn <ARN>

RDS

List all RDS engines

1
aws rds describe-db-engine-versions --output text --query 'DBEngineVersions[*].[Engine]' | uniq

List all RDS engine versions for PostgreSQL

1
aws rds describe-db-engine-versions --output text --filters "Name=engine,Values=postgres" --query 'DBEngineVersions[*].[EngineVersion]'

List all RDS families for PostgreSQL

1
aws rds describe-db-engine-versions --output text --filters "Name=engine,Values=postgres" --query 'DBEngineVersions[*].[DBParameterGroupFamily]' | uniq

List Aurora PostgreSQL serverless engines

1
2
aws rds describe-db-engine-versions --engine="aurora-postgresql" | \
  jq -r '.DBEngineVersions[] | select(.SupportedEngineModes[] | contains("serverless"))'

STS

Get account ID

1
 aws sts get-caller-identity --output text --query Account 

Random

Get every IP range used by AWS in the US regions

1
curl -sSL https://ip-ranges.amazonaws.com/ip-ranges.json | jq -r '.prefixes[] | select(.region|test("us-")) | .ip_prefix