Cloudformation

Create cloudformation stack with parameter file (note, parameter file has to be json)

aws cloudformation create-stack --stack-name dirks-sample-stack --template-body file://dirks-sample-stack.json --parameters file://dirks-sample-stack-dev.json

# or

aws cloudformation create-stack --stack-name dirks-sample-stack --template-body file://dirks-sample-stack.yaml --parameters file://dirks-sample-stack-dev.json

Show all resources created by cloudformation stacks with dirk in their name

for stack_name in $(aws cloudformation describe-stacks --query "Stacks[?contains(StackName, \`dirk\`)].StackName" --output text); do
  echo "Exporting resources for $stack_name"
  aws cloudformation list-stack-resources --stack-name $stack_name > created_resources/$stack_name
done

Trigger cloudformation stack drift detection for multiple stacks that contain in their name

for stack_name in $(aws cloudformation describe-stacks --query "Stacks[?contains(StackName, \`<pattern>\`)].StackName" --output text); do
  echo "Detecting drift for $stack_name"
  aws cloudformation detect-stack-drift --stack-name $stack_name
done
aws cloudformation describe-stacks --query "Stacks[?contains(StackName, \`<pattern>\`)].StackName" --output text|tr '\t' '\n'|sort

Cloudwatch

# query log groups
aws logs describe-log-groups --query "logGroups[].logGroupName"

# delete log group
aws logs delete-log-group --log-group-name "log-group-name"

SSM parameter store

# query parameters
aws ssm describe-parameters --query "Parameters[].Name"
aws ssm get-parameters-by-path --path "/your/path/"

# delete parameters
aws ssm delete-parameters --names "parameter1" "parameter2" 

Delete old Elastic Beanstalk versions

DELETE_DATE=2019 aws elasticbeanstalk describe-application-versions --output text|grep -w $DELETE_DATE |awk '{print "AWS_PROFILE=cio-iat aws elasticbeanstalk delete-application-version --application-name <your-application-name> --version-label " $7 " --delete-source-bundle"}'|bash -xv

Misc

List all records of a zone and export them to CSV

aws route53 list-resource-record-sets --hosted-zone-id <zone-id> | jq '.ResourceRecordSets[] | [.Name, .Type, .ResourceRecords[0].Value] | @csv'

API gateway: delete all API keys

for id in $(aws apigateway get-api-keys --name-query $1 --query "items[].id" --output text); do
  aws apigateway delete-api-key --api-key $id
done