Matt Hough
Matt Hough

Reputation: 1101

Creating EC2 instances from template with arguments

Let's say I have a webapp where users can click a button that starts a long running task (eg. 3 days long). The user can also select options, for example the things it wants that task to do.

No matter what, the task will be the same script that runs when the instance starts. However, I would like it to somehow take arguments from the button click to change the function of the startup script.

Is there a way to do this with AWS EC2 instances?

Upvotes: 1

Views: 247

Answers (2)

craigcaulfield
craigcaulfield

Reputation: 3538

This behaviour isn't directly related to EC2, although EC2 could host an application that does these long-running parameterised tasks. Whether EC2 is a good choice also depends on how your tasks react to underlying failures: if the EC2 instance fails or restarts, what happens to your task?

Depending on your use case, some managed options might be:

Upvotes: 1

John Rotenstein
John Rotenstein

Reputation: 270154

So, you're saying that you want to pass certain parameters to some software that will be launched on an EC2 instance.

There are many ways to do this:

  • When the instance is launched, you can pass User Data. This is commonly used to run a startup script, but it can also be used just to pass information to the instance that can be accessed via http://169.254.169.254/latest/user-data/. So, either pass the configuration directly or pass it as part of the startup script.
  • Store it in tags on the instance when the instance is launched. Once the software starts up, it can retrieve the tags associated with the instance (itself) and act appropriately.
  • Store the configuration in a database and have the software access the database to determine what it should do.
  • Store the configuration in Amazon S3 and have the software retrieve the configuration file.

Personally, I like the idea of Tags. It's very Cloud.

Upvotes: 2

Related Questions