views:

561

answers:

2

Hi I am developing the code to start an instance of an EC2 image on Amazon Web Services, there are 2 steps

1) start the instance 2) allocate our Elastic IP address to the started instance

Is there a way to carry out both of these in a single command?

I will be running a .bat file to start the instance, and then when the instance is running I will use the REST query API to call AssociateAddress. I'm not sure yet how best to determine when the started instance changes from pending to running other than making periodic calls to it. Am I able to associate an IP address to a pending instance?

Stephen

A: 

Sure, you'd need to add a startup script to your EC2 instance that runs the allocate-address command at boot time to do the association of the elastic IP. Here's a tutorial on adding startup / shutdown scripts to an EC2 instance.

gareth_bowles
Thanks, but we are running instances made available by a third party ... so Im not sure if we'd be able to add our script. Do you mean that the script would be added as part of the AMI and then when you launch the image it would start the script. Can i send the script when starting the instance?
undefined
Hmm, you might be in a bit of a catch-22 here - you can pass parameters to an inat stance when you launch it, but your AMI needs to have a startup script that accepts those parameters. Have a look at http://developer.amazonwebservices.com/connect/entry.jspa?externalID=1085 for how this works.
gareth_bowles
+1  A: 

Yes, you can assign the IP to the pending instance. It's handled from the firewalls and not your instance, so it doesn't need to be running to make the change. Your instance never actually knows about the Elastic IP.

Gary Richardson