ModifyImageAttributeCommand

Modifies the specified attribute of the specified AMI. You can specify only one attribute at a time.

To specify the attribute, you can use the Attribute parameter, or one of the following parameters: Description, ImdsSupport, or LaunchPermission.

Images with an Amazon Web Services Marketplace product code cannot be made public.

To enable the SriovNetSupport enhanced networking attribute of an image, enable SriovNetSupport on an instance and create an AMI from the instance.

Example Syntax

Use a bare-bones client and the command you need to make an API call.

import { EC2Client, ModifyImageAttributeCommand } from "@aws-sdk/client-ec2"; // ES Modules import
// const { EC2Client, ModifyImageAttributeCommand } = require("@aws-sdk/client-ec2"); // CommonJS import
const client = new EC2Client(config);
const input = { // ModifyImageAttributeRequest
  Attribute: "STRING_VALUE",
  Description: { // AttributeValue
    Value: "STRING_VALUE",
  },
  ImageId: "STRING_VALUE", // required
  LaunchPermission: { // LaunchPermissionModifications
    Add: [ // LaunchPermissionList
      { // LaunchPermission
        OrganizationArn: "STRING_VALUE",
        OrganizationalUnitArn: "STRING_VALUE",
        UserId: "STRING_VALUE",
        Group: "all",
      },
    ],
    Remove: [
      {
        OrganizationArn: "STRING_VALUE",
        OrganizationalUnitArn: "STRING_VALUE",
        UserId: "STRING_VALUE",
        Group: "all",
      },
    ],
  },
  OperationType: "add" || "remove",
  ProductCodes: [ // ProductCodeStringList
    "STRING_VALUE",
  ],
  UserGroups: [ // UserGroupStringList
    "STRING_VALUE",
  ],
  UserIds: [ // UserIdStringList
    "STRING_VALUE",
  ],
  Value: "STRING_VALUE",
  OrganizationArns: [ // OrganizationArnStringList
    "STRING_VALUE",
  ],
  OrganizationalUnitArns: [ // OrganizationalUnitArnStringList
    "STRING_VALUE",
  ],
  ImdsSupport: {
    Value: "STRING_VALUE",
  },
  DryRun: true || false,
};
const command = new ModifyImageAttributeCommand(input);
const response = await client.send(command);
// {};

Example Usage

 Loading code editorLoading code editor

ModifyImageAttributeCommand Input

Parameter
Type
Description
ImageId
Required
string | undefined

The ID of the AMI.

Attribute
string | undefined

The name of the attribute to modify.

Valid values: description | imdsSupport | launchPermission

Description
AttributeValue | undefined

A new description for the AMI.

DryRun
boolean | undefined

Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

ImdsSupport
AttributeValue | undefined

Set to v2.0 to indicate that IMDSv2 is specified in the AMI. Instances launched from this AMI will have HttpTokens automatically set to required so that, by default, the instance requires that IMDSv2 is used when requesting instance metadata. In addition, HttpPutResponseHopLimit is set to 2. For more information, see Configure the AMI  in the Amazon EC2 User Guide.

Do not use this parameter unless your AMI software supports IMDSv2. After you set the value to v2.0, you can't undo it. The only way to “reset” your AMI is to create a new AMI from the underlying snapshot.

LaunchPermission
LaunchPermissionModifications | undefined

A new launch permission for the AMI.

OperationType
OperationType | undefined

The operation type. This parameter can be used only when the Attribute parameter is launchPermission.

OrganizationArns
string[] | undefined

The Amazon Resource Name (ARN) of an organization. This parameter can be used only when the Attribute parameter is launchPermission.

OrganizationalUnitArns
string[] | undefined

The Amazon Resource Name (ARN) of an organizational unit (OU). This parameter can be used only when the Attribute parameter is launchPermission.

ProductCodes
string[] | undefined

Not supported.

UserGroups
string[] | undefined

The user groups. This parameter can be used only when the Attribute parameter is launchPermission.

UserIds
string[] | undefined

The Amazon Web Services account IDs. This parameter can be used only when the Attribute parameter is launchPermission.

Value
string | undefined

The value of the attribute being modified. This parameter can be used only when the Attribute parameter is description or imdsSupport.

ModifyImageAttributeCommand Output

Parameter
Type
Description
$metadata
Required
ResponseMetadata
Metadata pertaining to this request.

Throws

Name
Fault
Details
EC2ServiceException
Base exception class for all service exceptions from EC2 service.