How can I get the Image ID after importing a disk image?

0

Hello,

I am writing a program that imports a disk image in my S3 bucket as an AMI, and then creates an EC2 instance with that AMI.
I succeeded in using the AWS SDK for Java to do each task separately, but I struggle with going from the first step to the second step.
Specifically, I struggle with getting the Image ID of the AMI after the import task is complete. I need the Image ID of the AMI to make an EC2 instance. I was trying to use an ImportImageResult to get the information, but calling getImageID() would return null.

After sending an ImportImageRequest, I want to wait until the import is complete and the new AMI is available. Then, I want to get the Image ID of the new AMI. How can I do this programmatically, and is there a best way to do it?

emul8r
已提問 3 年前檢視次數 303 次
1 個回答
0

The trick is to regularly call DescribeImportImageTasks, find the specific task, call getStatus on it to see if it is "completed", and if not, wait a bit before calling DescribeImportImageTasks again, etc., until the task is finally complete. Then, calling getImageID on that task would not return null. In order to make the task findable, I gave it a specific description, but I suppose giving it a specific tag could also work.

emul8r
已回答 3 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南