Search code examples
boto3amazon-ami

AWS: How to create a public AMI from instance using Boto3?


I was able to find in the documentation on how to create AMI images from the running instance. But I am not able to change it to public visibility.

https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html?highlight=create%20image#EC2.Instance.create_image


Solution

  • If you look at the CLI example, you can do this via the command:

    aws ec2 modify-image-attribute --image-id ami-0abcdef1234567890 --launch-permission "Add=[{Group=all}]"

    So if you want to achieve this using Lambda, you need to use the modify_attribute, resource action.

    [1] https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html?highlight=create%20image#EC2.Image.modify_attribute