Skip to content

Instantly share code, notes, and snippets.

@kawaz
Created December 11, 2023 04:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kawaz/6728dc6aaecd590f99ae9a920c8c71eb to your computer and use it in GitHub Desktop.
Save kawaz/6728dc6aaecd590f99ae9a920c8c71eb to your computer and use it in GitHub Desktop.
Route53の全ゾーンの全レコードセットを取得するスクリプト
#!/bin/bash
set -e -o pipefail
# HostedZone[].Id を保存
aws route53 list-hosted-zones | jq .HostedZones[].Id -r | tee HostedZoneIds.txt
# 全HostedZoneのRecordSetを取得
while read id; do
aws route53 list-resource-record-sets --hosted-zone-id "$id"
done <HostedZoneIds.txt | tee rs.json.tmp
[[ $? == 0 ]] || exit
mv rs.json.tmp rs.json
# RecordSetリストをシンプルな形に加工
cat rs.json |
jq '.ResourceRecordSets[]|{Name,Type,v:"\(.ResourceRecords//[]|map(.Value)|join(","))\(.AliasTarget.DNSName//"")"}|.+{v:(.v|split(","))}' -c |
perl -pe's/\."/"/g' |
tee rs-digest.json |
grep -vE -e '"(SOA|NS|TXT|MX)"' -e '(acm-validations.aws)' |
jq .Name -r |
perl -pe's/\.$//' |
tee fqdns.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment