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 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则