本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
将 ModifyImageAttribute 与 CLI 配合使用
以下代码示例显示了如何使用 ModifyImageAttribute。
- CLI
-
- AWS CLI
-
示例 1:公开 AMI
以下
modify-image-attribute示例将公开指定的 AMI。aws ec2 modify-image-attribute \ --image-idami-5731123e\ --launch-permission"Add=[{Group=all}]"此命令不生成任何输出。
欲了解更多信息,请参阅 公开您的 AMI 以供在 Amazon EC2 中使用 在 亚马逊 EC2 用户指南。
示例 2:将 AMI 设为私有
以下
modify-image-attribute示例将指定的 AMI 设为私有。aws ec2 modify-image-attribute \ --image-idami-5731123e\ --launch-permission"Remove=[{Group=all}]"此命令不生成任何输出。
欲了解更多信息,请参阅 公开您的 AMI 以供在 Amazon EC2 中使用 在 亚马逊 EC2 用户指南。
示例 3:向... 授予启动权限 AWS 帐户
以下
modify-image-attribute示例向指定用户授予启动权限 AWS 账户。aws ec2 modify-image-attribute \ --image-idami-5731123e\ --launch-permission"Add=[{UserId=123456789012}]"此命令不生成任何输出。
欲了解更多信息,请参阅 与特定用户共享 AMI AWS 账户 在 亚马逊 EC2 用户指南。
示例 4:移除启动权限 AWS 帐户
以下
modify-image-attribute示例从指定文件中移除启动权限 AWS 账户。aws ec2 modify-image-attribute \ --image-idami-5731123e\ --launch-permission"Remove=[{UserId=123456789012}]"此命令不生成任何输出。
欲了解更多信息,请参阅 与特定用户共享 AMI AWS 账户 在 亚马逊 EC2 用户指南。
-
有关 API 的详细信息,请参阅 ModifyImageAttribute
在 AWS CLI 命令参考。
-
- PowerShell
-
- 用于 PowerShell V4
-
示例 1:此示例更新指定 AMI 的描述。
Edit-EC2ImageAttribute -ImageId ami-12345678 -Description "New description"示例 2:此示例将 AMI 设为公开(例如,so any AWS 账户 可以使用)。
Edit-EC2ImageAttribute -ImageId ami-12345678 -Attribute launchPermission -OperationType add -UserGroup all示例 3:此示例将 AMI 设为私有(例如,只有作为所有者的您才能使用它)。
Edit-EC2ImageAttribute -ImageId ami-12345678 -Attribute launchPermission -OperationType remove -UserGroup all示例 4:此示例向指定用户授予启动权限 AWS 账户。
Edit-EC2ImageAttribute -ImageId ami-12345678 -Attribute launchPermission -OperationType add -UserId 111122223333示例 5:此示例移除指定启动权限 AWS 账户。
Edit-EC2ImageAttribute -ImageId ami-12345678 -Attribute launchPermission -OperationType remove -UserId 111122223333-
有关 API 的详细信息,请参阅 ModifyImageAttribute 在 AWS Tools for PowerShell Cmdlet 参考手册 (V4)。
-
- 用于 PowerShell V5
-
示例 1:此示例更新指定 AMI 的描述。
Edit-EC2ImageAttribute -ImageId ami-12345678 -Description "New description"示例 2:此示例将 AMI 设为公开(例如,so any AWS 账户 可以使用)。
Edit-EC2ImageAttribute -ImageId ami-12345678 -Attribute launchPermission -OperationType add -UserGroup all示例 3:此示例将 AMI 设为私有(例如,只有作为所有者的您才能使用它)。
Edit-EC2ImageAttribute -ImageId ami-12345678 -Attribute launchPermission -OperationType remove -UserGroup all示例 4:此示例向指定用户授予启动权限 AWS 账户。
Edit-EC2ImageAttribute -ImageId ami-12345678 -Attribute launchPermission -OperationType add -UserId 111122223333示例 5:此示例移除指定启动权限 AWS 账户。
Edit-EC2ImageAttribute -ImageId ami-12345678 -Attribute launchPermission -OperationType remove -UserId 111122223333-
有关 API 的详细信息,请参阅 ModifyImageAttribute 在 AWS Tools for PowerShell Cmdlet 参考手册 (V5)。
-
如需查看完整清单 AWS SDK 开发者指南和代码示例,请参阅 使用 AWS SDK 创建 Amazon EC2 资源。本主题还包括有关入门的信息以及有关先前的 SDK 版本的详细信息。