Skip to content

put_object_lock_configuration

put_object_lock_configuration(
    bucket: BucketName,
    *,
    config_overrides: Optional[S3ClientConfig] = None,
    object_lock_configuration: Optional[ObjectLockConfiguration] = None,
    request_payer: Optional[RequestPayer] = None,
    token: Optional[ObjectLockToken] = None,
    content_md5: Optional[ContentMD5] = None,
    checksum_algorithm: Optional[ChecksumAlgorithm] = None,
    expected_bucket_owner: Optional[AccountId] = None,
) -> PutObjectLockConfigurationOutput

This operation is not supported for directory buckets.

Places an Object Lock configuration on the specified bucket. The rule specified in the Object Lock configuration will be applied by default to every new object placed in the specified bucket. For more information, see Locking Objects.

  • The DefaultRetention settings require both a mode and a period.

  • The DefaultRetention period can be either Days or Years but you must select one. You cannot specify Days and Years at the same time.

  • You can enable Object Lock for new or existing buckets. For more information, see Configuring Object Lock.

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 whose Object Lock configuration you want to create or replace.

  • object_lock_configuration (Optional[ObjectLockConfiguration], default: None ) –

    The Object Lock configuration that you want to apply to the specified bucket.

  • token (Optional[ObjectLockToken], default: None ) –

    A token to allow Object Lock to be enabled for an existing bucket.

  • 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_lock_configuration(
    self,
    bucket: "capo_s3.types.bucket_name.BucketName",
    *,
    config_overrides: Optional[S3ClientConfig] = None,
    object_lock_configuration: Optional[
        "capo_s3.types.object_lock_configuration.ObjectLockConfiguration"
    ] = None,
    request_payer: Optional["capo_s3.types.request_payer.RequestPayer"] = None,
    token: Optional["capo_s3.types.object_lock_token.ObjectLockToken"] = 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_lock_configuration_output.PutObjectLockConfigurationOutput":
    """<note> <p>This operation is not supported for directory buckets.</p> </note> <p>Places an Object Lock configuration on the specified bucket. The rule specified in the Object Lock configuration will be applied by default to every new object placed in the specified bucket. For more information, see <a href="https://docs.aws.amazon.com/AmazonS3/latest/dev/object-lock.html">Locking Objects</a>. </p> <note> <ul> <li> <p>The <code>DefaultRetention</code> settings require both a mode and a period.</p> </li> <li> <p>The <code>DefaultRetention</code> period can be either <code>Days</code> or <code>Years</code> but you must select one. You cannot specify <code>Days</code> and <code>Years</code> at the same time.</p> </li> <li> <p>You can enable Object Lock for new or existing buckets. For more information, see <a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lock-configure.html">Configuring Object Lock</a>.</p> </li> </ul> </note> <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 whose Object Lock configuration you want to create or replace.</p>
        object_lock_configuration: <p>The Object Lock configuration that you want to apply to the specified bucket.</p>
        token: <p>A token to allow Object Lock to be enabled for an existing bucket.</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_lock_configuration_request.PutObjectLockConfigurationRequest]",
    ) -> OperationResponse[
        "capo_s3.types.put_object_lock_configuration_output.PutObjectLockConfigurationOutput"
    ]:
        import capo_s3._operations.amazon_s3.put_object_lock_configuration

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

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("PutObjectLockConfiguration")
    )
    input_: capo_s3.types.put_object_lock_configuration_request.PutObjectLockConfigurationRequest = {
        "bucket": bucket
    }
    if object_lock_configuration is not None:
        input_["object_lock_configuration"] = object_lock_configuration
    if request_payer is not None:
        input_["request_payer"] = request_payer
    if token is not None:
        input_["token"] = token
    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