Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am experimenting with EC2 spot instances, and am needing some data to be retained between terminations. Now as I understand it, when the current price goes above my max. bid, it will be automatically terminated. I assume any init scripts I have will be run on shutdown so I can push data off to the EBS before unmounting.

My question is, how can I automatically mount the same EBS volume on the new spot instance once the price goes down, since it won't have any of my init scripts that I would've loaded onto the root volume the first time?

Do I have to create a custom AMI, or is there some other way to achieve this?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

If you simply want the instance to start out with a fixed starting point each time it runs, then you could:

  1. Create your own AMI and run that as the instance each time, or

  2. Specify a user-data script that installs and configures software to your specifications each time a new instance is started from a standard base AMI.

If you need to keep state between instance runs, then you'll need to save the data somewhere outside of the instance/AMI. For example:

  1. The data could be kept up to date on S3, SimpleDB, DynamoDB, RDS, etc.

  2. You could designate a permanent EBS volume that the instance dynamically attaches and mounts at startup. This could be done with a user-data script.

share|improve this answer
Specifying a user-data script that installs sounds interesting; How could this be done when a spot request starts a new instance automatically? I already have a permanent EBS volume storing data, and will probably continue to use that –  Jeff Nov 13 '12 at 2:51
When you create the spot request, you specify user-data that should be passed in to each new spot instance. –  Eric Hammond Nov 13 '12 at 23:34
Ah I did not realize with cloud-init putting #! first in user-data executed a script. Thank you –  Jeff Nov 14 '12 at 1:15
@Jeff: Yeah, I invented that and popular AMIs have adopted it :-) alestic.com/2009/06/ec2-user-data-scripts –  Eric Hammond Nov 14 '12 at 1:22
Along this line, is it possible to have a spot instance mount a particular EBS volume as its root disk when started? –  Derek Morrison Dec 5 '13 at 21:11

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.