AWS CLI – Notes

Some cli-fu to get required results from AWS using awscli. To execute these commands please make sure that awscli is configured on your system.

Get all DNS records from all Route53 hosted zones

for zone in `aws route53 list-hosted-zones | jq -r '.HostedZones[].Id'`; do \
    aws route53 list-resource-record-sets --hosted-zone-id $zone |\
    jq -r '.ResourceRecordSets[]? | "\(.Name),\(.Type),\(.ResourceRecords[]?.Value)"'; \
done

Get all dangling DNS records from all Route53 hosted zones

for zone in `aws route53 list-hosted-zones | jq -r '.HostedZones[].Id'`; do 
  aws route53 list-resource-record-sets --hosted-zone-id $zone --query "ResourceRecordSets[?Type == 'CNAME']" |\
  jq -r '.[].Name' |\
    while read record; do \
      if [[ $(host $record | grep 'not found') ]]; then \
        echo $record;
      fi;
    done;
done