Skip to content

Instantly share code, notes, and snippets.

@mrk21
Last active January 15, 2019 16:45
Show Gist options
  • Select an option

  • Save mrk21/3970c0ea1b4ff2bed9886659cd181be1 to your computer and use it in GitHub Desktop.

Select an option

Save mrk21/3970c0ea1b4ff2bed9886659cd181be1 to your computer and use it in GitHub Desktop.
Register private hosted zone
#!/bin/bash
# Register private hosted zone
# @see [aws 起動毎にローカル IP をローカル DNS (Route53) の A レコードに突っ込む - Qiita](https://qiita.com/selfnavi/items/a731514cd8174d86caf5)
INSTANCE_ID=`curl http://169.254.169.254/latest/meta-data/instance-id | sed -e 's/^i-//g'`
IPV4=`curl http://169.254.169.254/latest/meta-data/local-ipv4`
HOSTNAME=`echo "app-:instance-id:.example.local" | sed -e "s/:instance-id:/${INSTANCE_ID}/g"`
HOSTED_ZONE_ID=<hosted-zone-id>
cat <<JSON > /root/register-route53.json
{
"Comment": "${HOSTNAME}",
"Changes": [
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "${HOSTNAME}",
"Type": "A",
"TTL" : 3600 ,
"ResourceRecords": [{
"Value": "${IPV4}"
}]
}
}
]
}
JSON
aws route53 change-resource-record-sets --hosted-zone-id ${HOSTED_ZONE_ID} --change-batch file:///root/register-route53.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment