Skip to content

Instantly share code, notes, and snippets.

@kenners
Last active August 27, 2018 12:20
Show Gist options
  • Save kenners/0f59cb2ae4ac4dfd3e464003bffe9d5e to your computer and use it in GitHub Desktop.
Save kenners/0f59cb2ae4ac4dfd3e464003bffe9d5e to your computer and use it in GitHub Desktop.
Updates a AWS Route53 record with the machine's current IP address.
#!/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}"
@kenners
Copy link
Author

kenners commented Aug 27, 2018

The AWS IAM user running this command requires the following permissions:

  • route53:ChangeResourceRecordSets for the resource arn:aws:route53:::hostedzone/HOSTED_ZONE_ID
  • route53:GetChange for the resource arn:aws:route53:::change/*

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