Is it possible to pass a script while I’m starting an instance? So that the instance will execute that script once its initialized?
public static void startInstance(final String instanceId) {
StartInstancesRequest startRequest = new StartInstancesRequest().withInstanceIds(instanceId);
logger.info(String.format("Starting instance '%s':...", instanceId));
ec2.startInstances(startRequest);
}
Any idea? Script will be kind of startup script which I need to execute as soon as the instance is ready. Thanks in advance.
I introduced the concept of user-data scripts in the community Ubuntu AMIs in 2009 (simplified version of some ideas from RightScale):
It boils down to:
This feature was later included in the official Ubuntu AMIs in the CloudInit package:
Amazon now includes the CloudInit package in their own Amazon Linux AMIs:
Other distros are welcome to (and may already) include this feature in their AMIs.