如何使用boto/python更改AWS中的镜像权限(AMI)?

7
我们如何使用Python的boto模块,更改AMI的权限以添加更多的AWS账户?
2个回答

7
您可以使用boto.ec2模块的modify_image_attribute方法来修改与图像相关的其他属性。您可以像这样添加其他授权用户:
import boto.ec2

ec2 = boto.ec2.connect_to_region('<your region>')
ec2.modify_image_attribute('ami-12345678', operation='add', attribute='launchPermission', user_ids=['user_id_1', 'user_id_2'])

同样地,您可以使用attribute='launchPermission'和参数group_ids中的组值添加授权组。

出现TypeError: modify_image_attribute()只接受关键字参数错误。 - AR2

4

下面是使用 boto3 的方法:

    import boto3 

    ec2 = boto3.client("ec2")

    ACCOUNTS = [
        "123456789012",
        "123456789013",
    ]

    ec2.modify_image_attribute(
        Attribute='launchPermission',
        ImageId='ami-abc123',
        OperationType='add',
        UserIds=ACCOUNTS
    )

可以同时添加/删除用户/组,请查看文档获取更多详细信息和其他用例示例。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接