Last active
August 29, 2015 14:27
-
-
Save rc9000/87a7e0cfc3b9f1a42e0c to your computer and use it in GitHub Desktop.
Create route53 entry with the Name tag of an instance, as CNAME to the public DNS entry provided by AWS
This file contains 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 | |
# best to use a dedicated IAM user, see http://cantina.co/automated-dns-for-aws-instances-using-route-53/ | |
# for a guide | |
export AWS_ACCESS_KEY_ID="your access key" | |
export AWS_SECRET_ACCESS_KEY="your secret access key" | |
export ZONE="delegated-to-route53.example.com" | |
export TTL="600" | |
# get the aws cli with "pip install awscli" | |
# run aws configure first or create this manually, e.g. | |
# root@ip-172-31-14-23:~# cat ~/.aws/config | |
# [default] | |
# region = eu-central-1 | |
# aws_access_key_id = your access key | |
# aws_secret_access_key = your secret access key | |
shortname=$(aws ec2 describe-tags --filters "Name=resource-id,Values=$(ec2metadata --instance-id)" \ | |
--output text | grep Name | awk '{print $5}') | |
# ec2metadata comes with the default installation | |
target=$(ec2metadata --public-hostname) | |
# pip install cli53 | |
cli53 rrcreate $ZONE $shortname CNAME $target --replace --ttl $TTL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment