Skip to content

put_resource_policy

put_resource_policy(
    resource_arn: ResourceArn,
    resource_policy: ResourcePolicy,
    *,
    config_overrides: Optional[CloudTrailClientConfig] = None,
) -> PutResourcePolicyResponse

Attaches a resource-based permission policy to a CloudTrail event data store, dashboard, or channel. For more information about resource-based policies, see CloudTrail resource-based policy examples in the CloudTrail User Guide.

Parameters:

  • resource_arn (ResourceArn) –

    The Amazon Resource Name (ARN) of the CloudTrail event data store, dashboard, or channel attached to the resource-based policy.

    Example event data store ARN format: arn:aws:cloudtrail:us-east-2:123456789012:eventdatastore/EXAMPLE-f852-4e8f-8bd1-bcf6cEXAMPLE

    Example dashboard ARN format: arn:aws:cloudtrail:us-east-1:123456789012:dashboard/exampleDash

    Example channel ARN format: arn:aws:cloudtrail:us-east-2:123456789012:channel/01234567890

  • resource_policy (ResourcePolicy) –

    A JSON-formatted string for an Amazon Web Services resource-based policy.

    For example resource-based policies, see CloudTrail resource-based policy examples in the CloudTrail User Guide.

Raises:

  • ConflictException –

    This exception is thrown when the specified resource is not ready for an operation. This can occur when you try to run an operation on a resource before CloudTrail has time to fully load the resource, or because another operation is modifying the resource. If this exception occurs, wait a few minutes, and then try the operation again.

  • OperationNotPermittedException –

    This exception is thrown when the requested operation is not permitted.

  • ResourceARNNotValidException –

    This exception is thrown when the provided resource does not exist, or the ARN format of the resource is not valid.

    The following is the format of an event data store ARN: arn:aws:cloudtrail:us-east-2:123456789012:eventdatastore/EXAMPLE-f852-4e8f-8bd1-bcf6cEXAMPLE

    The following is the format of a dashboard ARN: arn:aws:cloudtrail:us-east-1:123456789012:dashboard/exampleDash

    The following is the format of a channel ARN: arn:aws:cloudtrail:us-east-2:123456789012:channel/01234567890

  • ResourceNotFoundException –

    This exception is thrown when the specified resource is not found.

  • ResourcePolicyNotValidException –

    This exception is thrown when the resouce-based policy has syntax errors, or contains a principal that is not valid.

  • ResourceTypeNotSupportedException –

    This exception is thrown when the specified resource type is not supported by CloudTrail.

  • UnsupportedOperationException –

    This exception is thrown when the requested operation is not supported.

  • UnknownServiceError –

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

Source code in docs_src/capo_cloudtrail/_services/cloud_trail.py
def put_resource_policy(
    self,
    resource_arn: "capo_cloudtrail.types.resource_arn.ResourceArn",
    resource_policy: "capo_cloudtrail.types.resource_policy.ResourcePolicy",
    *,
    config_overrides: Optional[CloudTrailClientConfig] = None,
) -> "capo_cloudtrail.types.put_resource_policy_response.PutResourcePolicyResponse":
    """<p> Attaches a resource-based permission policy to a CloudTrail event data store, dashboard, or channel. For more information about resource-based policies, see <a href="https://docs.aws.amazon.com/awscloudtrail/latest/userguide/security_iam_resource-based-policy-examples.html">CloudTrail resource-based policy examples</a> in the <i>CloudTrail User Guide</i>. </p>

    Args:
        resource_arn: <p> The Amazon Resource Name (ARN) of the CloudTrail event data store, dashboard, or channel attached to the resource-based policy.</p> <p>Example event data store ARN format: <code>arn:aws:cloudtrail:us-east-2:123456789012:eventdatastore/EXAMPLE-f852-4e8f-8bd1-bcf6cEXAMPLE</code> </p> <p>Example dashboard ARN format: <code>arn:aws:cloudtrail:us-east-1:123456789012:dashboard/exampleDash</code> </p> <p>Example channel ARN format: <code>arn:aws:cloudtrail:us-east-2:123456789012:channel/01234567890</code> </p>
        resource_policy: <p> A JSON-formatted string for an Amazon Web Services resource-based policy. </p> <p> For example resource-based policies, see <a href="https://docs.aws.amazon.com/awscloudtrail/latest/userguide/security_iam_resource-based-policy-examples.html">CloudTrail resource-based policy examples</a> in the <i>CloudTrail User Guide</i>.</p>

    Raises:
        capo_cloudtrail.errors.conflict_exception.ConflictException: <p>This exception is thrown when the specified resource is not ready for an operation. This can occur when you try to run an operation on a resource before CloudTrail has time to fully load the resource, or because another operation is modifying the resource. If this exception occurs, wait a few minutes, and then try the operation again.</p>
        capo_cloudtrail.errors.operation_not_permitted_exception.OperationNotPermittedException: <p>This exception is thrown when the requested operation is not permitted.</p>
        capo_cloudtrail.errors.resource_arn_not_valid_exception.ResourceARNNotValidException: <p> This exception is thrown when the provided resource does not exist, or the ARN format of the resource is not valid. </p> <p>The following is the format of an event data store ARN: <code>arn:aws:cloudtrail:us-east-2:123456789012:eventdatastore/EXAMPLE-f852-4e8f-8bd1-bcf6cEXAMPLE</code> </p> <p>The following is the format of a dashboard ARN: <code>arn:aws:cloudtrail:us-east-1:123456789012:dashboard/exampleDash</code> </p> <p>The following is the format of a channel ARN: <code>arn:aws:cloudtrail:us-east-2:123456789012:channel/01234567890</code> </p>
        capo_cloudtrail.errors.resource_not_found_exception.ResourceNotFoundException: <p>This exception is thrown when the specified resource is not found.</p>
        capo_cloudtrail.errors.resource_policy_not_valid_exception.ResourcePolicyNotValidException: <p> This exception is thrown when the resouce-based policy has syntax errors, or contains a principal that is not valid. </p>
        capo_cloudtrail.errors.resource_type_not_supported_exception.ResourceTypeNotSupportedException: <p>This exception is thrown when the specified resource type is not supported by CloudTrail.</p>
        capo_cloudtrail.errors.unsupported_operation_exception.UnsupportedOperationException: <p>This exception is thrown when the requested operation is not supported.</p>
        capo_cloudtrail.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

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

        output, http_response = (
            capo_cloudtrail._operations.cloud_trail_20131101.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_cloudtrail.types.put_resource_policy_request.PutResourcePolicyRequest = {
        "resource_arn": resource_arn,
        "resource_policy": resource_policy,
    }

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