【发布时间】:2020-09-15 07:21:13
【问题描述】:
我们如何更改 AMI 的权限以使用 python 的 boto 模块添加更多 AWS 账户?
【问题讨论】:
标签: amazon-web-services boto3 boto
我们如何更改 AMI 的权限以使用 python 的 boto 模块添加更多 AWS 账户?
【问题讨论】:
标签: amazon-web-services boto3 boto
您可以使用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. 失败
这是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 和其他用例示例。
【讨论】: