【问题标题】:How to change image permission (AMI) for AWS using boto/python?如何使用 boto/python 更改 AWS 的图像权限 (AMI)?
【发布时间】:2020-09-15 07:21:13
【问题描述】:

我们如何更改 AMI 的权限以使用 python 的 boto 模块添加更多 AWS 账户?

【问题讨论】:

    标签: amazon-web-services boto3 boto


    【解决方案1】:

    您可以使用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() only accepts keyword arguments. 失败
    【解决方案2】:

    这是boto3 的做法:

        import boto3 
    
        ec2 = boto3.client("ec2")
    
        ACCOUNTS = [
            "123456789012",
            "123456789013",
        ]
    
        ec2.modify_image_attribute(
            Attribute='launchPermission',
            ImageId='ami-abc123',
            OperationType='add',
            UserIds=ACCOUNTS
        )
    

    还有一些方法可以同时添加/删除用户/组,see the docs for more details 和其他用例示例。

    【讨论】:

      猜你喜欢
      • 2014-05-04
      • 2011-07-15
      • 1970-01-01
      • 2011-09-24
      • 1970-01-01
      • 2018-03-16
      • 2014-11-18
      • 1970-01-01
      • 2018-02-18
      相关资源
      最近更新 更多