Take the 2-minute tour ×

First of all I want to clarify that I am new to AWS and specifically to Spot Instances, so excuse my lack of specific language.

I have to achieve the following setup:

  • Create a spot instance every 8 hours
  • Run an R script each time (it takes about 35 minutes to run)
  • Write the results back to an RDS persistant instance I own (this happens inside the R script)
  • Shutdown the spot instnace

So far I have the "creating a spot instance every 8 hours" part working via the AWS SDK and a custom script.

The issue I am having is that I am not sure how can I run the R script inside the spot instance once it has become "active".

I understand how to check the status of the instance, but not how to "call" the file.

I thought on running a cron job on another machine which would check if the instance is active and call the file.

Is this the way to go? If it is, how can I get the instance address in order to call it?

share|improve this question
you dont say what language your custom script is written in, but chances are that it supports some sort of while loop...so seems like you could put a while AWS not active...wait 30 seconds...else run R script in there? –  Chase Sep 1 '12 at 23:05
Hi,thanks!I am writing on python,but it am open to php or java.The thing is that the file which checks the status of the spot is not on the spot itself, its on my side and is a cron which runs every 1 minute to check the status.The thing is that I dont know how can I call the R file once the status is set to active because I dont know the IP/address of the spot instanace. –  JordanBelf Sep 2 '12 at 0:51
add comment

1 Answer

up vote 3 down vote accepted

There is the CloudInit package available (at least on Ubuntu based AMIs) to execute various tasks at instance startup. You could write a shellscript and place it in the User-data section to execute it on startup, calling your R script. This should be easier than checking instance status from another machine.

share|improve this answer
Thanks so much! I was not aware about Cloudinit, it looks like what I need! –  JordanBelf Sep 2 '12 at 16:32
add comment

Your Answer


