Skip to content

put_image_policy async

put_image_policy(
    image_arn: ImageBuildVersionArn,
    policy: ResourcePolicyDocument,
    *,
    config_overrides: Optional[AsyncimagebuilderClientConfig] = None,
) -> PutImagePolicyResponse

Applies a policy to an image. The preferred way to share resources is with the RAM API CreateResourceShare. If you use the PutImagePolicy operation instead, you must also call the RAM API PromoteResourceShareCreatedFromPolicy. Otherwise, the resource isn't visible to the principals that it's shared with.

Parameters:

  • image_arn (ImageBuildVersionArn) –

    The Amazon Resource Name (ARN) of the image that this policy should be applied to.

  • policy (ResourcePolicyDocument) –

    The resource policy to apply to the image, as a JSON policy document. Image Builder validates the policy with Amazon Web Services RAM before applying it, and rejects invalid policies with InvalidParameterValueException.

Raises:

  • CallRateLimitExceededException –

    You have exceeded the permitted request rate for the Amazon EC2 APIs that Image Builder calls on your behalf. Retry with an increasing or variable delay between requests.

  • ClientException –

    A generic client error. This error usually indicates that the request failed a validation check, such as when a downstream service rejects a configured value.

  • ForbiddenException –

    You are not authorized to perform the requested operation.

  • InvalidParameterValueException –

    The value that you provided for the specified parameter is invalid.

  • InvalidRequestException –

    The request is malformed or otherwise invalid. Verify the request and try again.

  • ResourceNotFoundException –

    At least one of the resources referenced by your request does not exist.

  • ServiceException –

    An internal server error occurred while Image Builder processed the request. Retrying the request may succeed.

  • ServiceUnavailableException –

    The service is unable to process your request at this time.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Examples:

Share an image with another AWS account The following example applies a resource policy to an image build version that grants another AWS account permission to view the image.

>>> await client.put_image_policy(image_arn='arn:aws:imagebuilder:us-west-2:111122223333:image/my-example-recipe/1.0.0/1', policy='{"Version": "2012-10-17", "Statement": [{"Effect": "Allow", "Principal": {"AWS": "arn:aws:iam::444455556666:root"}, "Action": ["imagebuilder:GetImage", "imagebuilder:ListImages"], "Resource": ["arn:aws:imagebuilder:us-west-2:111122223333:image/my-example-recipe/1.0.0/1"]}]}')
Source code in docs_src/capo_imagebuilder/_services/async_imagebuilder.py
async def put_image_policy(
    self,
    image_arn: "capo_imagebuilder.types.image_build_version_arn.ImageBuildVersionArn",
    policy: "capo_imagebuilder.types.resource_policy_document.ResourcePolicyDocument",
    *,
    config_overrides: Optional[AsyncimagebuilderClientConfig] = None,
) -> "capo_imagebuilder.types.put_image_policy_response.PutImagePolicyResponse":
    """<p>Applies a policy to an image. The preferred way to share resources is with the RAM API <a href="https://docs.aws.amazon.com/ram/latest/APIReference/API_CreateResourceShare.html">CreateResourceShare</a>. If you use the PutImagePolicy operation instead, you must also call the RAM API <a href="https://docs.aws.amazon.com/ram/latest/APIReference/API_PromoteResourceShareCreatedFromPolicy.html">PromoteResourceShareCreatedFromPolicy</a>. Otherwise, the resource isn't visible to the principals that it's shared with.</p>

    Args:
        image_arn: <p>The Amazon Resource Name (ARN) of the image that this policy should be applied to.</p>
        policy: <p>The resource policy to apply to the image, as a JSON policy document. Image Builder validates the policy with Amazon Web Services RAM before applying it, and rejects invalid policies with <code>InvalidParameterValueException</code>.</p>

    Raises:
        capo_imagebuilder.errors.call_rate_limit_exceeded_exception.CallRateLimitExceededException: <p>You have exceeded the permitted request rate for the Amazon EC2 APIs that Image Builder calls on your behalf. Retry with an increasing or variable delay between requests.</p>
        capo_imagebuilder.errors.client_exception.ClientException: <p>A generic client error. This error usually indicates that the request failed a validation check, such as when a downstream service rejects a configured value.</p>
        capo_imagebuilder.errors.forbidden_exception.ForbiddenException: <p>You are not authorized to perform the requested operation.</p>
        capo_imagebuilder.errors.invalid_parameter_value_exception.InvalidParameterValueException: <p>The value that you provided for the specified parameter is invalid.</p>
        capo_imagebuilder.errors.invalid_request_exception.InvalidRequestException: <p>The request is malformed or otherwise invalid. Verify the request and try again.</p>
        capo_imagebuilder.errors.resource_not_found_exception.ResourceNotFoundException: <p>At least one of the resources referenced by your request does not exist.</p>
        capo_imagebuilder.errors.service_exception.ServiceException: <p>An internal server error occurred while Image Builder processed the request. Retrying the request may succeed.</p>
        capo_imagebuilder.errors.service_unavailable_exception.ServiceUnavailableException: <p>The service is unable to process your request at this time.</p>
        capo_imagebuilder.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        Share an image with another AWS account
        The following example applies a resource policy to an image build version that grants another AWS account permission to view the image.

        >>> await client.put_image_policy(image_arn='arn:aws:imagebuilder:us-west-2:111122223333:image/my-example-recipe/1.0.0/1', policy='{"Version": "2012-10-17", "Statement": [{"Effect": "Allow", "Principal": {"AWS": "arn:aws:iam::444455556666:root"}, "Action": ["imagebuilder:GetImage", "imagebuilder:ListImages"], "Resource": ["arn:aws:imagebuilder:us-west-2:111122223333:image/my-example-recipe/1.0.0/1"]}]}')
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_imagebuilder.types.put_image_policy_request.PutImagePolicyRequest]",
    ) -> AsyncOperationResponse[
        "capo_imagebuilder.types.put_image_policy_response.PutImagePolicyResponse"
    ]:
        import capo_imagebuilder._operations.imagebuilder.put_image_policy

        (
            output,
            http_response,
        ) = await capo_imagebuilder._operations.imagebuilder.put_image_policy.async_put_image_policy(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("PutImagePolicy")
    )
    input_: capo_imagebuilder.types.put_image_policy_request.PutImagePolicyRequest = {
        "image_arn": image_arn,
        "policy": policy,
    }

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