I would like to auto-assign an EIP to an instance when it is started. I know I can write a script to stop/start the instance and assign the EIP I want using the EC2 tools, but that depends on me stopping/starting the server. In the case of an EC2 outage or hardware failure where Amazon stops/starts my instance, the EIP would not be reassigned.

I asked someone this question before and they cryptically mentioned that it could be done via script from inside the box after boot. Then they went offline so I could not follow up.

Is there any way to tie an EIP to an instance at boot time?

link|improve this question

feedback

2 Answers

up vote 1 down vote accepted

Agree with Eric, that option is not wise in terms of security. Another option would be to have another machine, with credentials in it, in charge of responding to requests from other machines. E.g.: Machine with my credential is EC2-1. You launch perhaps 2 machines to run your web servers, EC2-2 and EC2-3. When they bootstrap, they can "signal" this to EC2-1, which in turn will run the API call to associate EC2-2 and EC2-3 to two Elastic IPs. This way, you have to make EC2-1 VERY secure, and you are not at risk with the other machines.

Best,

Simone

link|improve this answer
I thought about what @Erik Hammond mentioned last night and decided that putting my certs/keys on the servers in question was not acceptable because they are public web servers. However, this solution of having my servers call home to initiate an EIP association request fits very nicely with my infrastructure. I currently have a management server doing all sorts of tasks like this so it makes perfect sense for it to also do the EIP association. Thanks. – jdw Sep 29 '11 at 13:20
feedback

You can do it with something like this, in the /etc/rc.local on the server in question:

ec2-associate-address --private-key /root/private_key.pem --cert /root/public_key.pem <eip-address> -i `curl http://169.254.169.254/latest/meta-data/instance-id
link|improve this answer
Beauty, thanks. I am new to EC2 and just becoming aware of the meta data repository. Very useful stuff. – jdw Sep 28 '11 at 22:21
The above is only an option if you are willing to put AWS credentials on the instance itself (often considered a security risk). – Eric Hammond Sep 29 '11 at 0:34
For a solution to the credentials issue, see serverfault.com/a/368537/2111 – timday Mar 11 at 17:27
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.