jeffrey
jeffrey

Reputation: 3354

How to get the public DNS address of a second ec2 instance while inside the first instance

Building off of this question:

https://unix.stackexchange.com/questions/24355/is-there-a-way-to-get-the-public-dns-address-of-an-instance

I know how to get an ec2 instance's own public DNS address. What I need is a way for this instance to get the public DNS instance of a second ec2 instance.

The idea is that I will have ~50 instances running, one or two of which will be a spot instance that is constantly running. All of the other worker instances need to know the spot, or master, instance's public DNS name to connect to it within my application. How can I do this?

On another note, is there a way I can create a backup of my spot master instance? In case it fails, I would like to have another spot instance that immediately takes its place, but my worker ec2 instances would have to update their information about the spot instance's public dns address.

Upvotes: 1

Views: 264

Answers (2)

Barak
Barak

Reputation: 3066

An alternative is to use S3. When a spot instance comes up it will read its own public address and write it to a bucket in S3. The other instances will look up the bucket the first time they need it and use this value. If the spot instance goes down, the workers will poll the bucket periodically until a new spot instance comes up and updates the bucket.

Make sure to set the bucket to only allow authenticated access so only your applications can modify it.

This approach has a security advantage, as the VMs do not need access to your EC2 credentials. They only need access to a specific S3 bucket.

Upvotes: 0

Faris Zacina
Faris Zacina

Reputation: 14274

I think the only way to get the public DNS of your other instance is by using the command line interface or Web API provided by amazon.

The concrete command you need is ec2-describe-instances which provides data about public DNS settings for each instance.

http://docs.aws.amazon.com/AWSEC2/latest/CommandLineReference/ApiReference-cmd-DescribeInstances.html

Of course you can do the same through the Web API:

http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeInstances.html

Regarding the backup you can map the spot instance to EBS (which is preferrable) and then make snapshot backups. The snapshot backups are still triggered manually in the amazon console (or again through command line tools and Web API). Snapshots should be good for regular backups.

You can also use a service like http://www.skeddly.com/ to automate your EC2 snapshot backups.

If you want to backup the full AMI image of your spot instance, so you can re-create it from scratch at a later time, or create multiple instances from the same image etc. go to the management console and do the following:

  1. Click on Instances
  2. Select the instance you want to create an AMI from
  3. Click on "Actions" and select "Create Image"
  4. Set the Image name and other info and save

Upvotes: 1

Related Questions