Skip to content

Instantly share code, notes, and snippets.

@uemuraj
Last active April 24, 2019 23:07
Show Gist options
  • Save uemuraj/7ea92eaa1964b20e9b7b4b2ac71e08a0 to your computer and use it in GitHub Desktop.
Save uemuraj/7ea92eaa1964b20e9b7b4b2ac71e08a0 to your computer and use it in GitHub Desktop.
aws route53 change-resource-record-sets をラップする簡単なシェルスクリプト
#!/bin/bash
DOMAIN=$1
ZONE_ID=$(aws route53 list-hosted-zones-by-name --dns-name ${DOMAIN:?} --output text | grep -o -P "/hostedzone/[A-Z0-9]+")
CHANGE_ID=$(aws route53 change-resource-record-sets --hosted-zone-id ${ZONE_ID:?} --change-batch file:///dev/stdin --output text | grep -o -P "/change/[A-Z0-9]+")
if [ -z $CHANGE_ID ]; then
exit 1
fi
while aws route53 get-change --id $CHANGE_ID --output text | grep PENDING
do
sleep 10s
done
aws route53 get-change --id $CHANGE_ID --output text | grep INSYNC
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"route53:GetHostedZone",
"route53:ListHostedZonesByName",
"route53:ChangeResourceRecordSets",
"route53:GetChange"
],
"Resource": [
"*"
]
}
]
}
@uemuraj
Copy link
Author

uemuraj commented Nov 7, 2018

こんな感じで使えます:

$ ./aws-route53-change-resource-record-sets.sh hogehgoe.info. << EOF
{
  "Comment": "Setting up the TXT records",
  "Changes": [
    {
      "Action": "CREATE",
      "ResourceRecordSet": {
        "Name": "host.hogehoge.info.",
        "Type": "TXT",
        "TTL": 300,
        "ResourceRecords": [
          { "Value": "\"fuga\"" }
        ]
      }
    }
  ]
}
EOF
CHANGEINFO      Setting up the TXT records      /change/C3A8W6YB4CKU1Q  PENDING 2018-11-07T07:36:34.088Z
CHANGEINFO      Setting up the TXT records      /change/C3A8W6YB4CKU1Q  PENDING 2018-11-07T07:36:34.088Z
CHANGEINFO      Setting up the TXT records      /change/C3A8W6YB4CKU1Q  PENDING 2018-11-07T07:36:34.088Z
CHANGEINFO      Setting up the TXT records      /change/C3A8W6YB4CKU1Q  INSYNC  2018-11-07T07:36:34.088Z

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment