I'm a long time developer but not very experienced with DNS. Here's my problem:
Our app launches servers on Amazon EC2 for clients. One client wants to use custom DNS's for every server launched instead of the normal long public DNS provided by AWS: for example server-5.demo.ourclient.com, server-6.demo.ourclient.com.
What's the easiest/cleanest/b开发者_开发问答est way to solve this challenge from inside our application that launches the servers and knows the Amazon public DNS? We can probably get control of demo.ourclient.com as well....
Are there nice hosted solutions with API's? Would we need to manage a DNS server for *.demo.ourclient.com?
Thanks!
Chad
Even better would be to use Route53, which is Amazon's Dynamic DNS service: http://aws.amazon.com/documentation/route53/
You could try one of the dynamic dns services. These allow you to define your own host names such as machine1.dyndns.org and attach that to an IP address. There are scripts you can run to update the dyndns resolver with the dynamic IP address provided by EC2.
I don't really understand why your client wouldn't either use an Elastic IP here, or an Elastic Load Balancer?
With an Elastic IP, you can keep a consistent name on your public DNS record and then manually or programmatically update the EC2 instance associated with that EIP whenever necessary using the elb API scripts.
With an Elastic Load Balancer, you could easily have just one active node attached to the ELB, and then could programmatically drop/add nodes and update Route53 accordingly.
You could use the internal machine's API to get the values (Instance ID, etc.) for these calls in a boostrap script.
This code gets your ip, and then sets it in route53. You have to provide the variables DOMAIN and HOSTED_ZONE_ID. You could run this at start up. If you don't want to rely on ifconfig.co, instead do
DOMAIN="desired.domain.com"
HOSTED_ZONE_ID="..."
# ANYWHERE, but relies on ifconfig.co
MYIP=$(curl -s ifconfig.co)
# ON EC2:
MYIP=$(curl -s curl 169.254.169.254/latest/meta-data/public-ipv4)
# create json to send to route53
cat > /tmp/actual_ip.json <<EOF
{
"Comment": "Update the A record set",
"Changes": [
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "$DOMAIN",
"Type": "A",
"TTL": 300,
"ResourceRecords": [
{
"Value": "$MYIP"
}
]
}
}
]
}
EOF
# update the dns entry
if ! /usr/local/bin/aws route53 change-resource-record-sets --hosted-zone-id $HOSTED_ZONE_ID --change-batch file:///tmp/actual_ip.json; then
echo "error calling aws $?"
fi
精彩评论