There are more AWS SDK examples available in the AWS Doc SDK Examples
Use ModifyImageAttribute with a CLI
The following code examples show how to use ModifyImageAttribute.
- CLI
-
- AWS CLI
-
Example 1: To make an AMI public
The following
modify-instance-attributeexample makes the specified AMI public.aws ec2 modify-image-attribute \ --image-idami-5731123e\ --launch-permission"Add=[{Group=all}]"This command produces no output.
Example 2: To make an AMI private
The following
modify-instance-attributeexample makes the specified AMI private.aws ec2 modify-image-attribute \ --image-idami-5731123e\ --launch-permission"Remove=[{Group=all}]"This command produces no output.
Example 3: To grant launch permission to an AWS account
The following
modify-instance-attributeexample grants launch permissions to the specified AWS account.aws ec2 modify-image-attribute \ --image-idami-5731123e\ --launch-permission"Add=[{UserId=123456789012}]"This command produces no output.
Example 4: To remove launch permission from an AWS account
The following
modify-instance-attributeexample removes launch permissions from the specified AWS account.aws ec2 modify-image-attribute \ --image-idami-5731123e\ --launch-permission"Remove=[{UserId=123456789012}]"-
For API details, see ModifyImageAttribute
in AWS CLI Command Reference.
-
- PowerShell
-
- Tools for PowerShell V4
-
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 AWS account can use it).
Edit-EC2ImageAttribute -ImageId ami-12345678 -Attribute launchPermission -OperationType add -UserGroup allExample 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 allExample 4: This example grants launch permission to the specified AWS account.
Edit-EC2ImageAttribute -ImageId ami-12345678 -Attribute launchPermission -OperationType add -UserId 111122223333Example 5: This example removes launch permission from the specified AWS account.
Edit-EC2ImageAttribute -ImageId ami-12345678 -Attribute launchPermission -OperationType remove -UserId 111122223333-
For API details, see ModifyImageAttribute in AWS Tools for PowerShell Cmdlet Reference (V4).
-
- Tools for PowerShell V5
-
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 AWS account can use it).
Edit-EC2ImageAttribute -ImageId ami-12345678 -Attribute launchPermission -OperationType add -UserGroup allExample 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 allExample 4: This example grants launch permission to the specified AWS account.
Edit-EC2ImageAttribute -ImageId ami-12345678 -Attribute launchPermission -OperationType add -UserId 111122223333Example 5: This example removes launch permission from the specified AWS account.
Edit-EC2ImageAttribute -ImageId ami-12345678 -Attribute launchPermission -OperationType remove -UserId 111122223333-
For API details, see ModifyImageAttribute in AWS Tools for PowerShell Cmdlet Reference (V5).
-