Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 618
David Rubin Avatar asked Apr 03 '12 20:04

David Rubin


People also ask

How do I know if my EC2 instance is working?

Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/ . In the navigation pane, choose Instances. On the Instances page, the Status check column lists the operational status of each instance. To view the status of a specific instance, select the instance, and then choose the Status checks tab.

How can you check on the status of this AWS service?

Check the AWS Service Health Dashboard if you're unable to reach an AWS service or console, such as the Amazon EC2 console. AWS services are Regional, so be sure to select your AWS Region from the dropdown list. The Service Health Dashboard displays information about service disruptions and open events.


1 Answers

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.

like image 151
bwight Avatar answered Sep 17 '22 09:09

bwight