AWS:如何使用 Boto3 从实例创建 public AMI?

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

我能够在文档中找到有关如何从 运行 实例创建 AMI 映像的信息。但我无法将其更改为 public 可见性。

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

如果您查看 CLI 示例,您可以通过以下命令执行此操作:

aws ec2 修改图像属性 --image-id ami-0abcdef1234567890 --launch-permission "Add=[{Group=all}]"

因此,如果您想使用 Lambda 实现此目的,则需要使用 modify_attribute、资源操作。

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