Created
February 26, 2017 00:47
-
-
Save waltervargas/5fb607f11b8ce68406d26bd8ca3d6417 to your computer and use it in GitHub Desktop.
AWS Userdata script to create/update route53 private hosted zone record for ec2 instance.
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
| # Update route53 record | |
| localip=$(curl -fs http://169.254.169.254/latest/meta-data/local-ipv4) | |
| hostedzoneid=$(aws route53 list-hosted-zones-by-name --dns-name ${Env}.${AWS::Region}.aws.example.com --query 'HostedZones[0].Id' | cut -d / -f 3 | tr -d '"') | |
| file=/tmp/record.json | |
| cat << EOF > $file | |
| { | |
| "Comment": "Update the A record set", | |
| "Changes": [ | |
| { | |
| "Action": "UPSERT", | |
| "ResourceRecordSet": { | |
| "Name": "jenkins.${Env}.${AWS::Region}.aws.example.com", | |
| "Type": "A", | |
| "TTL": 300, | |
| "ResourceRecords": [ | |
| { | |
| "Value": "$localip" | |
| } | |
| ] | |
| } | |
| } | |
| ] | |
| } | |
| EOF | |
| aws route53 change-resource-record-sets --hosted-zone-id $hostedzoneid --change-batch file://$file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment