Skip to content

modify_image_attribute async

modify_image_attribute(
    *,
    config_overrides: Optional[AsyncEC2ClientConfig] = None,
    attribute: Optional[String] = None,
    description: Optional[AttributeValue] = None,
    image_id: Optional[ImageId] = None,
    launch_permission: Optional[LaunchPermissionModifications] = None,
    operation_type: Optional[OperationType] = None,
    product_codes: Optional[ProductCodeStringList] = None,
    user_groups: Optional[UserGroupStringList] = None,
    user_ids: Optional[UserIdStringList] = None,
    value: Optional[String] = None,
    organization_arns: Optional[OrganizationArnStringList] = None,
    organizational_unit_arns: Optional[OrganizationalUnitArnStringList] = None,
    imds_support: Optional[AttributeValue] = None,
    dry_run: Optional[Boolean] = None,
) -> None

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.

Parameters:

  • attribute (Optional[String], default: None ) –

    The name of the attribute to modify.

    Valid values: description | imdsSupport | launchPermission

  • description (Optional[AttributeValue], default: None ) –

    A new description for the AMI.

  • image_id (Optional[ImageId], default: None ) –

    The ID of the AMI.

  • launch_permission (Optional[LaunchPermissionModifications], default: None ) –

    A new launch permission for the AMI.

  • operation_type (Optional[OperationType], default: None ) –

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

  • product_codes (Optional[ProductCodeStringList], default: None ) –

    Not supported.

  • user_groups (Optional[UserGroupStringList], default: None ) –

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

  • user_ids (Optional[UserIdStringList], default: None ) –

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

  • value (Optional[String], default: None ) –

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

  • organization_arns (Optional[OrganizationArnStringList], default: None ) –

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

  • organizational_unit_arns (Optional[OrganizationalUnitArnStringList], default: None ) –

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

  • imds_support (Optional[AttributeValue], default: None ) –

    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.

  • dry_run (Optional[Boolean], default: None ) –

    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.

Raises:

Examples:

To grant launch permissions This example grants launch permissions for the specified AMI to the specified AWS account.

>>> await client.modify_image_attribute(image_id='ami-5731123e', launch_permission={'Add': [{'UserId': '123456789012'}]})
To make an AMI public
This example makes the specified AMI public.
>>> await client.modify_image_attribute(image_id='ami-5731123e', launch_permission={'Add': [{'Group': 'all'}]})
Source code in docs_src/capo_ec2/_services/async_ec2.py
async def modify_image_attribute(
    self,
    *,
    config_overrides: Optional[AsyncEC2ClientConfig] = None,
    attribute: Optional["capo_ec2.types.string.String"] = None,
    description: Optional["capo_ec2.types.attribute_value.AttributeValue"] = None,
    image_id: Optional["capo_ec2.types.image_id.ImageId"] = None,
    launch_permission: Optional[
        "capo_ec2.types.launch_permission_modifications.LaunchPermissionModifications"
    ] = None,
    operation_type: Optional["capo_ec2.types.operation_type.OperationType"] = None,
    product_codes: Optional[
        "capo_ec2.types.product_code_string_list.ProductCodeStringList"
    ] = None,
    user_groups: Optional[
        "capo_ec2.types.user_group_string_list.UserGroupStringList"
    ] = None,
    user_ids: Optional[
        "capo_ec2.types.user_id_string_list.UserIdStringList"
    ] = None,
    value: Optional["capo_ec2.types.string.String"] = None,
    organization_arns: Optional[
        "capo_ec2.types.organization_arn_string_list.OrganizationArnStringList"
    ] = None,
    organizational_unit_arns: Optional[
        "capo_ec2.types.organizational_unit_arn_string_list.OrganizationalUnitArnStringList"
    ] = None,
    imds_support: Optional["capo_ec2.types.attribute_value.AttributeValue"] = None,
    dry_run: Optional["capo_ec2.types.boolean.Boolean"] = None,
) -> None:
    """<p>Modifies the specified attribute of the specified AMI. You can specify only one attribute at a time.</p> <p>To specify the attribute, you can use the <code>Attribute</code> parameter, or one of the following parameters: <code>Description</code>, <code>ImdsSupport</code>, or <code>LaunchPermission</code>.</p> <p>Images with an Amazon Web Services Marketplace product code cannot be made public.</p> <p>To enable the SriovNetSupport enhanced networking attribute of an image, enable SriovNetSupport on an instance and create an AMI from the instance.</p>

    Args:
        attribute: <p>The name of the attribute to modify.</p> <p>Valid values: <code>description</code> | <code>imdsSupport</code> | <code>launchPermission</code> </p>
        description: <p>A new description for the AMI.</p>
        image_id: <p>The ID of the AMI.</p>
        launch_permission: <p>A new launch permission for the AMI.</p>
        operation_type: <p>The operation type. This parameter can be used only when the <code>Attribute</code> parameter is <code>launchPermission</code>.</p>
        product_codes: <p>Not supported.</p>
        user_groups: <p>The user groups. This parameter can be used only when the <code>Attribute</code> parameter is <code>launchPermission</code>.</p>
        user_ids: <p>The Amazon Web Services account IDs. This parameter can be used only when the <code>Attribute</code> parameter is <code>launchPermission</code>.</p>
        value: <p>The value of the attribute being modified. This parameter can be used only when the <code>Attribute</code> parameter is <code>description</code> or <code>imdsSupport</code>.</p>
        organization_arns: <p>The Amazon Resource Name (ARN) of an organization. This parameter can be used only when the <code>Attribute</code> parameter is <code>launchPermission</code>.</p>
        organizational_unit_arns: <p>The Amazon Resource Name (ARN) of an organizational unit (OU). This parameter can be used only when the <code>Attribute</code> parameter is <code>launchPermission</code>.</p>
        imds_support: <p>Set to <code>v2.0</code> to indicate that IMDSv2 is specified in the AMI. Instances launched from this AMI will have <code>HttpTokens</code> automatically set to <code>required</code> so that, by default, the instance requires that IMDSv2 is used when requesting instance metadata. In addition, <code>HttpPutResponseHopLimit</code> is set to <code>2</code>. For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-IMDS-new-instances.html#configure-IMDS-new-instances-ami-configuration">Configure the AMI</a> in the <i>Amazon EC2 User Guide</i>.</p> <important> <p>Do not use this parameter unless your AMI software supports IMDSv2. After you set the value to <code>v2.0</code>, you can't undo it. The only way to “reset” your AMI is to create a new AMI from the underlying snapshot.</p> </important>
        dry_run: <p>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 <code>DryRunOperation</code>. Otherwise, it is <code>UnauthorizedOperation</code>.</p>

    Raises:
        capo_ec2.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To grant launch permissions
        This example grants launch permissions for the specified AMI to the specified AWS account.

        >>> await client.modify_image_attribute(image_id='ami-5731123e', launch_permission={'Add': [{'UserId': '123456789012'}]})
        To make an AMI public
        This example makes the specified AMI public.

        >>> await client.modify_image_attribute(image_id='ami-5731123e', launch_permission={'Add': [{'Group': 'all'}]})
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_ec2.types.modify_image_attribute_request.ModifyImageAttributeRequest]",
    ) -> AsyncOperationResponse[None]:
        import capo_ec2._operations.amazon_ec2.modify_image_attribute

        (
            output,
            http_response,
        ) = await capo_ec2._operations.amazon_ec2.modify_image_attribute.async_modify_image_attribute(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("ModifyImageAttribute")
    )
    input_: capo_ec2.types.modify_image_attribute_request.ModifyImageAttributeRequest = {}
    if attribute is not None:
        input_["attribute"] = attribute
    if description is not None:
        input_["description"] = description
    if image_id is not None:
        input_["image_id"] = image_id
    if launch_permission is not None:
        input_["launch_permission"] = launch_permission
    if operation_type is not None:
        input_["operation_type"] = operation_type
    if product_codes is not None:
        input_["product_codes"] = product_codes
    if user_groups is not None:
        input_["user_groups"] = user_groups
    if user_ids is not None:
        input_["user_ids"] = user_ids
    if value is not None:
        input_["value"] = value
    if organization_arns is not None:
        input_["organization_arns"] = organization_arns
    if organizational_unit_arns is not None:
        input_["organizational_unit_arns"] = organizational_unit_arns
    if imds_support is not None:
        input_["imds_support"] = imds_support
    if dry_run is not None:
        input_["dry_run"] = dry_run

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output