Created
November 26, 2016 15:40
-
-
Save monitorjbl/529774e653814280ec1d358086d3cca1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# | |
# 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