AWS Code Snippets

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
    

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