Skip to content

put_object_legal_hold

put_object_legal_hold(
    bucket: BucketName,
    key: ObjectKey,
    *,
    config_overrides: Optional[S3ClientConfig] = None,
    legal_hold: Optional[ObjectLockLegalHold] = None,
    request_payer: Optional[RequestPayer] = None,
    version_id: Optional[ObjectVersionId] = None,
    content_md5: Optional[ContentMD5] = None,
    checksum_algorithm: Optional[ChecksumAlgorithm] = None,
    expected_bucket_owner: Optional[AccountId] = None,
) -> PutObjectLegalHoldOutput

This operation is not supported for directory buckets.

Applies a legal hold configuration to the specified object. For more information, see Locking Objects.

This functionality is not supported for Amazon S3 on Outposts.

You must URL encode any signed header values that contain spaces. For example, if your header value is my file.txt, containing two spaces after my, you must URL encode this value to my%20%20file.txt.

Parameters:

  • bucket (BucketName) –

    The bucket name containing the object that you want to place a legal hold on.

    Access points - When you use this action with an access point for general purpose buckets, you must provide the alias of the access point in place of the bucket name or specify the access point ARN. When you use this action with an access point for directory buckets, you must provide the access point name in place of the bucket name. When using the access point ARN, you must direct requests to the access point hostname. The access point hostname takes the form AccessPointName-AccountId.s3-accesspoint.Region.amazonaws.com. When using this action with an access point through the Amazon Web Services SDKs, you provide the access point ARN in place of the bucket name. For more information about access point ARNs, see Using access points in the Amazon S3 User Guide.

  • key (ObjectKey) –

    The key name for the object that you want to place a legal hold on.

  • legal_hold (Optional[ObjectLockLegalHold], default: None ) –

    Container element for the legal hold configuration you want to apply to the specified object.

  • version_id (Optional[ObjectVersionId], default: None ) –

    The version ID of the object that you want to place a legal hold on.

  • content_md5 (Optional[ContentMD5], default: None ) –

    The MD5 hash for the request body.

    For requests made using the Amazon Web Services Command Line Interface (CLI) or Amazon Web Services SDKs, this field is calculated automatically.

  • checksum_algorithm (Optional[ChecksumAlgorithm], default: None ) –

    Indicates the algorithm used to create the checksum for the object when you use the SDK. This header will not provide any additional functionality if you don't use the SDK. When you send this header, there must be a corresponding x-amz-checksum or x-amz-trailer header sent. Otherwise, Amazon S3 fails the request with the HTTP status code 400 Bad Request. For more information, see Checking object integrity in the Amazon S3 User Guide.

    If you provide an individual checksum, Amazon S3 ignores any provided ChecksumAlgorithm parameter.

  • expected_bucket_owner (Optional[AccountId], default: None ) –

    The account ID of the expected bucket owner. If the account ID that you provide does not match the actual owner of the bucket, the request fails with the HTTP status code 403 Forbidden (access denied).

Raises:

Source code in docs_src/capo_s3/_services/s3.py
def put_object_legal_hold(
    self,
    bucket: "capo_s3.types.bucket_name.BucketName",
    key: "capo_s3.types.object_key.ObjectKey",
    *,
    config_overrides: Optional[S3ClientConfig] = None,
    legal_hold: Optional[
        "capo_s3.types.object_lock_legal_hold.ObjectLockLegalHold"
    ] = None,
    request_payer: Optional["capo_s3.types.request_payer.RequestPayer"] = None,
    version_id: Optional["capo_s3.types.object_version_id.ObjectVersionId"] = None,
    content_md5: Optional["capo_s3.types.content_md5.ContentMD5"] = None,
    checksum_algorithm: Optional[
        "capo_s3.types.checksum_algorithm.ChecksumAlgorithm"
    ] = None,
    expected_bucket_owner: Optional["capo_s3.types.account_id.AccountId"] = None,
) -> "capo_s3.types.put_object_legal_hold_output.PutObjectLegalHoldOutput":
    """<note> <p>This operation is not supported for directory buckets.</p> </note> <p>Applies a legal hold configuration to the specified object. For more information, see <a href="https://docs.aws.amazon.com/AmazonS3/latest/dev/object-lock.html">Locking Objects</a>.</p> <p>This functionality is not supported for Amazon S3 on Outposts.</p> <important> <p>You must URL encode any signed header values that contain spaces. For example, if your header value is <code>my file.txt</code>, containing two spaces after <code>my</code>, you must URL encode this value to <code>my%20%20file.txt</code>.</p> </important>

    Args:
        bucket: <p>The bucket name containing the object that you want to place a legal hold on. </p> <p> <b>Access points</b> - When you use this action with an access point for general purpose buckets, you must provide the alias of the access point in place of the bucket name or specify the access point ARN. When you use this action with an access point for directory buckets, you must provide the access point name in place of the bucket name. When using the access point ARN, you must direct requests to the access point hostname. The access point hostname takes the form <i>AccessPointName</i>-<i>AccountId</i>.s3-accesspoint.<i>Region</i>.amazonaws.com. When using this action with an access point through the Amazon Web Services SDKs, you provide the access point ARN in place of the bucket name. For more information about access point ARNs, see <a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-access-points.html">Using access points</a> in the <i>Amazon S3 User Guide</i>.</p>
        key: <p>The key name for the object that you want to place a legal hold on.</p>
        legal_hold: <p>Container element for the legal hold configuration you want to apply to the specified object.</p>
        version_id: <p>The version ID of the object that you want to place a legal hold on.</p>
        content_md5: <p>The MD5 hash for the request body.</p> <p>For requests made using the Amazon Web Services Command Line Interface (CLI) or Amazon Web Services SDKs, this field is calculated automatically.</p>
        checksum_algorithm: <p>Indicates the algorithm used to create the checksum for the object when you use the SDK. This header will not provide any additional functionality if you don't use the SDK. When you send this header, there must be a corresponding <code>x-amz-checksum</code> or <code>x-amz-trailer</code> header sent. Otherwise, Amazon S3 fails the request with the HTTP status code <code>400 Bad Request</code>. For more information, see <a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html">Checking object integrity</a> in the <i>Amazon S3 User Guide</i>.</p> <p>If you provide an individual checksum, Amazon S3 ignores any provided <code>ChecksumAlgorithm</code> parameter.</p>
        expected_bucket_owner: <p>The account ID of the expected bucket owner. If the account ID that you provide does not match the actual owner of the bucket, the request fails with the HTTP status code <code>403 Forbidden</code> (access denied).</p>

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

    def _handler(
        req: "OperationRequest[capo_s3.types.put_object_legal_hold_request.PutObjectLegalHoldRequest]",
    ) -> OperationResponse[
        "capo_s3.types.put_object_legal_hold_output.PutObjectLegalHoldOutput"
    ]:
        import capo_s3._operations.amazon_s3.put_object_legal_hold

        output, http_response = (
            capo_s3._operations.amazon_s3.put_object_legal_hold.put_object_legal_hold(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("PutObjectLegalHold")
    )
    input_: capo_s3.types.put_object_legal_hold_request.PutObjectLegalHoldRequest = {
        "bucket": bucket,
        "key": key,
    }
    if legal_hold is not None:
        input_["legal_hold"] = legal_hold
    if request_payer is not None:
        input_["request_payer"] = request_payer
    if version_id is not None:
        input_["version_id"] = version_id
    if content_md5 is not None:
        input_["content_md5"] = content_md5
    if checksum_algorithm is not None:
        input_["checksum_algorithm"] = checksum_algorithm
    if expected_bucket_owner is not None:
        input_["expected_bucket_owner"] = expected_bucket_owner

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