Created
March 5, 2018 12:17
-
-
Save anapsix/c481b16a654d8e6edec2f855bee1763c to your computer and use it in GitHub Desktop.
export route53 in BINDish format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
case $1 in | |
--name) | |
shift | |
zonename="$1" | |
hostedzoneid=($(aws route53 list-hosted-zones | jq -r ".HostedZones[] | select(.Name == \"$zonename.\") | .Id" | cut -d'/' -f3)) | |
if [ ${#hostedzoneid[@]} -eq 0 ]; then | |
echo >&2 "Could not find Route53 zone for \"$zonename\", exiting.." | |
exit 1 | |
elif [ ${#hostedzoneid[@]} -gt 1 ]; then | |
echo >&2 "Found multiple Route53 zones for \"$zonename\", select one and rerun with explicit id selected" | |
echo >&2 "Zone ids: ${hostedzoneid[@]}" | |
echo >&2 "For example: $0 --id ${hostedzoneid}" | |
exit 1 | |
fi | |
;; | |
--id) | |
shift | |
hostedzoneid="$1" | |
;; | |
*) | |
echo >&2 "Usage: $0 [ --name example.org | --id E2F3HDS0RJPBV ]" | |
echo >&2 ' pass either "hosted zone name" or "hosted zone id"' | |
exit 1 | |
esac | |
aws route53 list-resource-record-sets --hosted-zone-id $hostedzoneid --output json | jq -jr '.ResourceRecordSets[] | "\(.Name) \t\(.TTL) \t\(.Type) \t \(if .AliasTarget then .AliasTarget.DNSName else .ResourceRecords[].Value end)\n"' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment