Skip to content

put_resource_policy

put_resource_policy(
    resource_arn: ComprehendModelArn,
    resource_policy: Policy,
    *,
    config_overrides: Optional[ComprehendClientConfig] = None,
    policy_revision_id: Optional[PolicyRevisionId] = None,
) -> PutResourcePolicyResponse

Attaches a resource-based policy to a custom model. You can use this policy to authorize an entity in another Amazon Web Services account to import the custom model, which replicates it in Amazon Comprehend in their account.

Parameters:

  • resource_arn (ComprehendModelArn) –

    The Amazon Resource Name (ARN) of the custom model to attach the policy to.

  • resource_policy (Policy) –

    The JSON resource-based policy to attach to your custom model. Provide your JSON as a UTF-8 encoded string without line breaks. To provide valid JSON for your policy, enclose the attribute names and values in double quotes. If the JSON body is also enclosed in double quotes, then you must escape the double quotes that are inside the policy:

    "{\"attribute\": \"value\", \"attribute\": [\"value\"]}"

    To avoid escaping quotes, you can use single quotes to enclose the policy and double quotes to enclose the JSON names and values:

    '{"attribute": "value", "attribute": ["value"]}'

  • policy_revision_id (Optional[PolicyRevisionId], default: None ) –

    The revision ID that Amazon Comprehend assigned to the policy that you are updating. If you are creating a new policy that has no prior version, don't use this parameter. Amazon Comprehend creates the revision ID for you.

Raises:

Source code in docs_src/capo_comprehend/_services/comprehend.py
def put_resource_policy(
    self,
    resource_arn: "capo_comprehend.types.comprehend_model_arn.ComprehendModelArn",
    resource_policy: "capo_comprehend.types.policy.Policy",
    *,
    config_overrides: Optional[ComprehendClientConfig] = None,
    policy_revision_id: Optional[
        "capo_comprehend.types.policy_revision_id.PolicyRevisionId"
    ] = None,
) -> "capo_comprehend.types.put_resource_policy_response.PutResourcePolicyResponse":
    r"""<p>Attaches a resource-based policy to a custom model. You can use this policy to authorize an entity in another Amazon Web Services account to import the custom model, which replicates it in Amazon Comprehend in their account.</p>

    Args:
        resource_arn: <p>The Amazon Resource Name (ARN) of the custom model to attach the policy to.</p>
        resource_policy: <p>The JSON resource-based policy to attach to your custom model. Provide your JSON as a UTF-8 encoded string without line breaks. To provide valid JSON for your policy, enclose the attribute names and values in double quotes. If the JSON body is also enclosed in double quotes, then you must escape the double quotes that are inside the policy:</p> <p> <code>"{\"attribute\": \"value\", \"attribute\": [\"value\"]}"</code> </p> <p>To avoid escaping quotes, you can use single quotes to enclose the policy and double quotes to enclose the JSON names and values:</p> <p> <code>'{"attribute": "value", "attribute": ["value"]}'</code> </p>
        policy_revision_id: <p>The revision ID that Amazon Comprehend assigned to the policy that you are updating. If you are creating a new policy that has no prior version, don't use this parameter. Amazon Comprehend creates the revision ID for you.</p>

    Raises:
        capo_comprehend.errors.internal_server_exception.InternalServerException: <p>An internal server error occurred. Retry your request.</p>
        capo_comprehend.errors.invalid_request_exception.InvalidRequestException: <p>The request is invalid.</p>
        capo_comprehend.errors.resource_not_found_exception.ResourceNotFoundException: <p>The specified resource ARN was not found. Check the ARN and try your request again.</p>
        capo_comprehend.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_comprehend.types.put_resource_policy_request.PutResourcePolicyRequest]",
    ) -> OperationResponse[
        "capo_comprehend.types.put_resource_policy_response.PutResourcePolicyResponse"
    ]:
        import capo_comprehend._operations.comprehend_20171127.put_resource_policy

        output, http_response = (
            capo_comprehend._operations.comprehend_20171127.put_resource_policy.put_resource_policy(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("PutResourcePolicy")
    )
    input_: capo_comprehend.types.put_resource_policy_request.PutResourcePolicyRequest = {
        "resource_arn": resource_arn,
        "resource_policy": resource_policy,
    }
    if policy_revision_id is not None:
        input_["policy_revision_id"] = policy_revision_id

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output