You need to run custom scripts each time a new instance is started.
user_data feature to pass scripts and/or data
to your newly started instance.
Once you get beyond the experimentation phase with EC2, you will quickly find that in addition to just starting an instance, you want to prepare that instance for a particular task. Why would you be starting an instance if you didn’t have an important job for it to perform? It turns out there are two main schools of thought regarding how best to accomplish this:
This approach focuses on starting with a plain vanilla image and then configuring all of the required software necessary to perform the desired task. Once everything is installed and configured, you create a new image based on this fully configured image, and that becomes the image that you use. When an instance based on this image is started, it has everything it needs to perform its task.
This approach also starts with a plain vanilla image, but all of the installation and configuration is done when the instance starts up. This could be accomplished with scripts and/or data that are passed the instance at startup time, or it could use a more sophisticated, centralized configuration service like Puppet or Chef.
Deciding which is right for you is a trade-off. Custom images provide quick start time and fewer dependencies but are less flexible. Each time you want to update ...