You can configure a new instance of EC2 at startup using official Ubuntu AMIs, official Amazon Linux AMIs, and any other AMI that supports the user data script concept.
Create a script (bash, Perl, Python,
- anything) that starts with C #!
- Pass this script as user data when starting the EC2 instance.
- The script starts automatically with root privileges on first boot.
Here's an article in which I introduced the concept of user data script:
Automate the installation of an EC2 instance using user data scripts
http://alestic.com/2009/06/ec2-user-data-scripts
Your user script data can install the necessary software, configure it, install your script work, and set up a cron job that runs the script once a day.
GAIN:
If the installation of the script does not take much time (for example, less than an hour or several), you do not even need to run a separate dedicated instance 24 hours a day. Instead, you can use an approach that allows AWS to run the instance for you on a regular schedule.
The article I wrote contains detailed information about this approach using sample commands:
Starting EC2 instances in a recurring schedule with automatic scaling
http://alestic.com/2011/11/ec2-schedule-instance
A general approach is to use automatic scaling to run an instance with user script data on a regular schedule. Your work will finish the instance when it is completed. They should suspend the usual desire for automatic scaling to restart instances that end so that you do not pay for the instance that is running until the next run of the job.
source share