Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to automatically assign an Elastic IP address to a spot instance that has a persistent spot request using the 'Advanced' 'User Data' script box?

I'm thinking that I could craft a script like...


# Credentials
export AWS_ACCESS_KEY=(insert key here) 
export AWS_SECRET_KEY=(insert key here) 

# EC2 Instance ID
instanceid=`/usr/bin/curl -s` 

# Associate EIP with the captured instance ID.
ec2-associate-address -i $instanceid (insert EIP here)

And stick this in the user data box (using web gui) before I finalize my spot request. Any thoughts or better methods for this? I don't need to autoscale, just using this one instance that comes up and down depending on spot prices but I'd like it to retain the same IP each time it comes back.

share|improve this question
i do something similar for normal non-vpc instances using an EIP tag on the instance. So i think your method is sound. – Sirex Dec 4 '13 at 21:12
up vote 0 down vote accepted

Recently, I also thought about automating the process of re-assigning an Elastic IP to my spot instance. After some Internet research, I have found several solid how-to resources on the topic:

  3. third link will be in the comment, as I don't have yet enough points to post more than 2 links

Hope this helps!

share|improve this answer
Third link: (not exactly a HOWTO, but still might be useful). – Aleksandr Blekh May 9 '14 at 22:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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