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년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠