除了輪詢,如何判斷長時間運行的Amazon EC2操作何時完成?例如,使用CreateImage
API函數可能需要幾分鐘的時間。我如何知道Amazon EC2操作何時完成?
現在我這樣做:
// 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
我討厭這樣。在致電CreateImage
之後,我想通過某種方式通知它已完成並繼續前進。這可能嗎?在本例中,我使用的是AWS .NET SDK,但我沒有專門尋找C#解決方案。
UPDATE:跨發佈到AWS Forums