Use ModifyImageAttribute with an Amazon SDK or CLI - Amazon Elastic Compute Cloud
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Use ModifyImageAttribute with an Amazon SDK or CLI

The following code examples show how to use ModifyImageAttribute.

CLI
Amazon CLI

Example 1: To make an AMI public

The following modify-instance-attribute example makes the specified AMI public.

aws ec2 modify-image-attribute \ --image-id ami-5731123e \ --launch-permission "Add=[{Group=all}]"

This command produces no output.

Example 2: To make an AMI private

The following modify-instance-attribute example makes the specified AMI private.

aws ec2 modify-image-attribute \ --image-id ami-5731123e \ --launch-permission "Remove=[{Group=all}]"

This command produces no output.

Example 3: To grant launch permission to an Amazon account

The following modify-instance-attribute example grants launch permissions to the specified Amazon account.

aws ec2 modify-image-attribute \ --image-id ami-5731123e \ --launch-permission "Add=[{UserId=123456789012}]"

This command produces no output.

Example 4: To remove launch permission from an Amazon account

The following modify-instance-attribute example removes launch permissions from the specified Amazon account.

aws ec2 modify-image-attribute \ --image-id ami-5731123e \ --launch-permission "Remove=[{UserId=123456789012}]"
PowerShell
Tools for PowerShell

Example 1: This example updates the description for the specified AMI.

Edit-EC2ImageAttribute -ImageId ami-12345678 -Description "New description"

Example 2: This example makes the AMI public (for example, so any Amazon Web Services account can use it).

Edit-EC2ImageAttribute -ImageId ami-12345678 -Attribute launchPermission -OperationType add -UserGroup all

Example 3: This example makes the AMI private (for example, so that only you as the owner can use it).

Edit-EC2ImageAttribute -ImageId ami-12345678 -Attribute launchPermission -OperationType remove -UserGroup all

Example 4: This example grants launch permission to the specified Amazon Web Services account.

Edit-EC2ImageAttribute -ImageId ami-12345678 -Attribute launchPermission -OperationType add -UserId 111122223333

Example 5: This example removes launch permission from the specified Amazon Web Services account.

Edit-EC2ImageAttribute -ImageId ami-12345678 -Attribute launchPermission -OperationType remove -UserId 111122223333

For a complete list of Amazon SDK developer guides and code examples, see Create Amazon EC2 resources using an Amazon SDK. This topic also includes information about getting started and details about previous SDK versions.