skip to Main Content

I’m trying to automate the creation of an autoscaling group Cloudformation Template using an EC2 instance already deployed and running so, for making an exact copy I need to have the AMI of the current instance. In order to get the Image I run the following script:

ec2 = boto3.client('ec2')
ec2.create_image(InstanceId="i-f234nr1kdd", Name="abc")

and it works, now what I need is to get the AMI Id using boto3 and the AMI name for pass the AMI Id to the cloudformation template.

I just need to get the AMI id value programmatically with the AMI name as parameter in order to pass the AMI Id to the part of my code that generates the Cloudformation template

Thanks since now!

2

Answers


  1. response = ec2.create_image(InstanceId="i-f234nr1kdd", Name="abc")
    response['ImageId']
    
    Login or Signup to reply.
  2. The docs here: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html#EC2.Client.create_image indicate that the id of the AMI is in the dictionary returned by the method call.

    It should be in response["ImageId"]

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search