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?
You can do it with something like this, in the /etc/rc.local on the server in question:
Use a VPC, then you won't have to worry about that problem.
Here is a bash i wrote to change EIP on any VPC Instance by using the friendly Name="tag", you can also specify a default region, or add it into the command.
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