How do I know when an Amazon EC2 operation is complete?

Go To StackoverFlow.com

5

Besides polling, how can I tell when a long-running Amazon EC2 operation is complete? For example, using the CreateImage API function can take upwards of several minutes.

Right now I'm doing this:

// MAKE THE API CALL
var createRequest = new CreateImageRequest().WithInstanceId("i-123456").WithName("MyNewAMI");
var createResponse = myAmazonEC2Client.CreateImage(createRequest);
var imageId = createResponse.CreateImageResult.ImageId;

// ICKY POLLING CODE
bool isImaging = true;
while (isImaging)
{
    var describeRequest = new DescribeImagesRequest().WithImageId(imageId);
    var describeResponse = myAmazonEC2Client.DescribeImages(describeRequest);
    isImaging = describeResponse.DescribeImagesResult.Image.Single().ImageState == "pending";
    Thread.Sleep(10000); // sleep for 10 seconds
}

// CreateImage IS COMPLETE; MOVE ON WITH OUR WORK

I hate this. After calling CreateImage, I'd like to just get notified somehow that it's all done and move on. Is this possible? I'm using the AWS .NET SDK in this example, but I'm not looking specifically for a C# solution.

UPDATE: Cross-posted to the AWS Forums

2012-04-03 20:19
by David Rubin


3

Some events in amazon can be configured to send notifications to an SNS Topic. For example when using auto scaling you can have notifications when a server is launched and terminated. As far as I know there is no way to trigger these notifications for other services such as CreateImage. I've looked for this type of feature in the past with no luck. I was trying to do it to create a script that would launch servers in a specific order. I wound up just polling their API as I couldn't find any way to register to those events.

2012-04-03 21:02
by bwight


0

James Hunter Ross answered this question over on the AWS Forums as follows:

Polling is it. That said, since you have a C# program started, why not let it spawn a polling process that notifies you as you wish? It seems you are almost done, in some respects.

(Of course, it would be nice if such functionality was built-in at AWS.)

I wasn't able to find a StackOverflow profile for him, but if he shows up I'll edit this to give him credit.

2012-04-05 22:06
by David Rubin
Ads