Skip to content

Instantly share code, notes, and snippets.

@monitorjbl
Created November 26, 2016 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monitorjbl/529774e653814280ec1d358086d3cca1 to your computer and use it in GitHub Desktop.
Save monitorjbl/529774e653814280ec1d358086d3cca1 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Updates a hosted zone in Route53 to point to the current IP address
# of this host.
#
# Usage: route53-identity.sh ZTDR0AEDW myhost.mydomain.com
#
ZONE_ID=$1
DOMAIN_NAME=$2
TMP_FILE=/tmp/aws.json
IP_ADDR=$(ifconfig | awk '/inet addr/{print substr($2,6)}' | grep -v 127.0.0.1 | xargs echo -n)
TEMPLATE='
{
"Comment": "",
"Changes": [
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "",
"Type": "A",
"TTL": 300,
"ResourceRecords": [
{
"Value": ""
}
]
}
}
]
}
'
rm -f $TMP_FILE
echo "$TEMPLATE" | python -c "
import json
import sys
obj=json.load(sys.stdin)
obj['Changes'][0]['ResourceRecordSet']['Name'] = '$DOMAIN_NAME.'
obj['Changes'][0]['ResourceRecordSet']['ResourceRecords'][0]['Value'] = '$IP_ADDR'
print json.dumps(obj)" > $TMP_FILE
aws route53 change-resource-record-sets --hosted-zone-id $ZONE_ID --change-batch file://$TMP_FILE
rm -f $TMP_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment