Last active
August 27, 2018 12:20
-
-
Save kenners/0f59cb2ae4ac4dfd3e464003bffe9d5e to your computer and use it in GitHub Desktop.
Updates a AWS Route53 record with the machine's current IP address.
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 | |
set -o nounset # Treat unset variables as an error when performing parameter expansion | |
set -o errexit # Halt script on error | |
set -o xtrace # Print a trace of simple commands and their arguments after expansion and before execution | |
HOSTED_ZONE_ID=YOUR_HOSTED_ZONE_ID | |
DNS_NAME=WWW.EXAMPLE.COM | |
IP=$(curl -s https://checkip.amazonaws.com) | |
CHANGE_ID=$(aws route53 change-resource-record-sets \ | |
--hosted-zone-id "${HOSTED_ZONE_ID}" \ | |
--change-batch file://<(echo "{ \"Changes\": [ { | |
\"Action\": \"UPSERT\", | |
\"ResourceRecordSet\": { | |
\"Name\": \"${DNS_NAME}\", | |
\"Type\": \"A\", | |
\"TTL\": 300, | |
\"ResourceRecords\": [ { | |
\"Value\": \"${IP}\" | |
}]}}]}") \ | |
--output text --query ChangeInfo.Id) | |
aws route53 wait resource-record-sets-changed --id "${CHANGE_ID}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The AWS IAM user running this command requires the following permissions:
route53:ChangeResourceRecordSets
for the resourcearn:aws:route53:::hostedzone/HOSTED_ZONE_ID
route53:GetChange
for the resourcearn:aws:route53:::change/*