Monthly Archives: December 2012

Creating a an instance in EC2 with .net and passing parameters


When starting an Amazon EC2 instance, you can pass something called “user metadata”.  This can be a file or values.  These values are not stored in an environmental variable or file on the new instance, but can instead be retrieved by doing a HTTP Get to a “special” IP address to retrieve those values.

For example:

1.  Create the instance

RunInstancesResponse response = Client.RunInstances(new RunInstancesRequest()
  .WithUserData(Convert.ToBase64String(Encoding.UTF8.GetBytes(bootScript.Replace("\r", ""))))

2.  In a startup script on the instance, make a call like this:

1234,fred,reboot,true | 4512,jimbo, | 173,,,

See the links below for further info