Amazon Web Services Tips
No Title[an error occurred while processing this directive]
Reference: Cisco: Internetworking Basics
On a normal startup, every Amazon EC2 instance will come with a private IP address, a dynamic Internet routable public IP address assigned from DHCP, and a dynamic domain name (hostname) associated with the public IP address. Access to the virtual server is provided through either the dynamic public IP address or the dynamic domain name. When the instance is started again, the default action is to assign another dynamic IP address (and new domain name) to the public IP address from DHCP. The same public IP address and domain name will not be associated with the instance on a restart. This is highly undesirable when the virtual servers are running critical services and needs to be restarted. For example, if one of the EC2 instances were running a web application and needed to be restarted, it would be unreachable by its previous domain name and public IP address. This could cause a significant amount of down-time if DNS had to be re-configured and updates needed to be propagated, especially if the application relies on inter-server communication.
One method to reduce down-time related with instance reboots is to automatically associate an Amazon Elastic IP address with the EC2 instance on startup. An Elastic IP address is a static IP address that can be assigned to an instance on startup using an EC2 startup script and user data. The Elastic IP address is entered into your DNS and provides a consistent domain name and IP address to access the virtual server. Although an Elastic IP address is free of charge while it is associated with a running instance, if an Elastic IP address is allocated and is not associated with an instance, the cost is $0.01/hr (at the time of this writing).
Another approach is to use a dynamic DNS resolution service which is the method described in this guide. This approach does not use a static IP address like when using an Elastic IP address but rather updates a DNS record configured with a dynamic DNS resolution service with the dynamic public IP address assigned to the EC2 instance when it starts. DynDNS and ZoneEdit are two popular dynamic DNS resolution services that work well with Amazon EC2 instances. Using DynDNS, you would first create a place holder record entry (domain name and dummy IP address) for your domain that you expect to be updated dynamically when the instance starts. For example, I would create an A-record with a static domain name (i.e. vmlinux1.aws-idev.com) and set the IP address to some phony value like 10.10.10.10. The IP address for this entry will be updated with the dynamic public IP address assigned to the instance when it starts. This provides a persistent domain name that can be used to access the virtual server each time it is started.
This guide provides instructions on using DynDNS. I felt that DynDNS offered better support and documentation on how to use their service. I also believe after researching the other alternatives that DynDNS provided better instructions on how to install and update clients using their ddclient utility.
Perform the following prerequisites on the target EC2 instance.
If you haven't already done so, create a Dyn account.
Sign up for either the DynDNS Pro or the Dyn Standard DNS service. Use the Dyn Standard DNS service if you have an existing domain or will be creating a new domain using their Domain Registration process. Note that Dyn offered a free non-commercial DNS account in the past; however, as of November 2011 that program has been deprecated.
In this guide, I am signed up for the Dyn Standard DNS service and will be using the domain aws-idev.com.
If using the Dyn Standard DNS service, log in to your Dyn account to add or create a domain (zone). From My Account, click on My Services and then click Add Zone Service to add or create your domain.
Figure 1: DynDNS - Zone Level Services
Create a place holder record for the DNS entry that you expect to be updated dynamically when the instance starts. In the following example, I will create a new A-record for the domain name vmlinux1.aws-idev.com along with a phony IP address. The IP address for this entry will be updated with the dynamic public IP address assigned to the instance when it starts.
Figure 2: DynDNS - Add Hostname
Install and configure DynDNS on the target EC2 instance.
The DynDNS client (ddclient) requires the perl-IO-Socket-SSL module.
Download the ddclient client software from the DynDNS website or by using wget.
Extract the ddclient client software and copy the appropriate files.
Modify the /etc/ddclient/ddclient.conf configuration file and change the hostnames, logins, and passwords where appropriate. For example:
Copy the following file when using Redhat style rc files and using daemon-mode:
Enable automatic startup of ddclient when booting the EC2 instance.
Optional: Create a startup script on the target EC2 instance that will manually change the hostname when the instance starts.
Update the runlevel information for the new system service.
Manually start ddclient for the first time.
When the service starts, it will automatically update the IP address for the domain name you created in DynDNS (i.e. vmlinux1.aws-idev.com) with the dynamic public IP address of the EC2 instance within 60 seconds.
Figure 3: DynDNS - Verify DynDNS IP Address Updated
Stop and Start the target EC2 instance to verify the domain name you created in DynDNS gets updated with the newly assigned dynamic public IP address of the instance. Do not test this by rebooting the instance. Rebooting an EC2 instance will use the same IP addresses from the previous session.
Figure 4: DynDNS - Verify DynDNS IP Address Updated
Now, every time the instance boots, it will update the appropriate entry in DynDNS with the new public IP address assigned to the instance. This provides a consistent hostname that can be used to access the virtual server.
Jeffrey Hunter is an Oracle Certified Professional, Java Development Certified Professional, Author, and an Oracle ACE. Jeff currently works as a Senior Database Administrator for The DBA Zone, Inc. located in Pittsburgh, Pennsylvania. His work includes advanced performance tuning, Java and PL/SQL programming, developing high availability solutions, capacity planning, database security, and physical / logical database design in a UNIX / Linux server environment. Jeff's other interests include mathematical encryption theory, tutoring advanced mathematics, programming language processors (compilers and interpreters) in Java and C, LDAP, writing web-based database administration tools, and of course Linux. He has been a Sr. Database Administrator and Software Engineer for over 20 years and maintains his own website site at: http://www.iDevelopment.info. Jeff graduated from Stanislaus State University in Turlock, California, with a Bachelor's degree in Computer Science and Mathematics.
Copyright (c) 1998-2017 Jeffrey M. Hunter. All rights reserved.
All articles, scripts and material located at the Internet address of http://www.idevelopment.info is the copyright of Jeffrey M. Hunter and is protected under copyright laws of the United States. This document may not be hosted on any other site without my express, prior, written permission. Application to host any of the material elsewhere can be made by contacting me at email@example.com.
I have made every effort and taken great care in making sure that the material included on my web site is technically accurate, but I disclaim any and all responsibility for any loss, damage or destruction of data or any other property which may arise from relying on it. I will in no case be liable for any monetary damages arising from such loss, damage or destruction.
Last modified on
Wednesday, 21-Nov-2012 18:21:26 EST
Page Count: 674