Last active
August 29, 2015 14:04
-
-
Save proger/49e7ae550f4e2d4c99af to your computer and use it in GitHub Desktop.
register a local hostname of an ec2 instance at route53 hosted zone (expects an IAM role)
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
# bash, coreutils, curl, awk, jq, openssl | |
zone=ZOZONEZONEZONE | |
date=$(curl -s -I https://route53.amazonaws.com/date | awk '/^Date: / {sub("Date: ", "", $0); sub("\\r", "", $0); print $0}') | |
set -- $(curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/dns | jq -r '.SecretAccessKey, .AccessKeyId, .Token') | |
signature=$(echo -n $date | openssl dgst -binary -sha1 -hmac $1 | base64) | |
auth_header="X-Amzn-Authorization: AWS3-HTTPS AWSAccessKeyId=$2,Algorithm=HmacSHA1,Signature=$signature" | |
hostname=$(hostname).doge-networking-enterprises.com | |
local_hostname=$(curl -s http://169.254.169.254/latest/meta-data/local-hostname) | |
{ cat <<EOF | |
<?xml version="1.0" encoding="UTF-8"?> | |
<ChangeResourceRecordSetsRequest xmlns="https://route53.amazonaws.com/doc/2013-04-01/"> | |
<ChangeBatch> | |
<Changes> | |
<Change> | |
<Action>UPSERT</Action> | |
<ResourceRecordSet> | |
<Name>$hostname</Name> | |
<Type>CNAME</Type> | |
<TTL>30</TTL> | |
<ResourceRecords> | |
<ResourceRecord><Value>$local_hostname</Value></ResourceRecord> | |
</ResourceRecords> | |
</ResourceRecordSet> | |
</Change> | |
</Changes> | |
</ChangeBatch> | |
</ChangeResourceRecordSetsRequest> | |
EOF | |
} | curl -d @/dev/stdin -H "Content-Type: text/xml" -H "x-amz-date: $date" -H "$auth_header" -H "x-amz-security-token: $3" -X POST https://route53.amazonaws.com/2013-04-01/hostedzone/$zone/rrset |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment