Skip to content

Object Lock object retention period

Estimated time to read: 1 minute

On this page you can find information about using Object Lock object operations.

Creating objects with Object Lock requires a bucket with Object Lock enabled. Enable Object Lock.

Object Lock bucket retention period object legal hold

Create an object with Object Lock

If there is a default Object Lock retention period on the bucket, you can create an object without any extra action. See:

aws s3api put-object --bucket <bucket_name> --key <object_name> \
    --body <file_name>

Get the retention period of an object

Retrieve the Object Lock retention:

aws s3api get-object-retention --bucket <bucket_name> --key <object_name>
---
{
    "Retention": {
        "Mode": "GOVERNANCE",
        "RetainUntilDate": "YYYY-MM-DDT00:00:00Z"
    }
}

Set or modify the retention period on an object

It is possible to update or set a retention period different than the default retention period of the bucket on an object.

aws s3api put-object-retention --bucket locked-bucket --key myfile.txt \
    --retention '
{
    "Mode": "GOVERNANCE",
    "RetainUntilDate": "YYYY-MM-DDT00:00:00Z"
}'

Remove the retention period on an object

It is possible to remove the retention period (only with GOVERNANCE mode) with:

aws s3api put-object-retention --bucket <bucket_name> --key <object_name> \
    --bypass-governance \
    --retention '
{ 
    "Mode": "GOVERNANCE", 
    "RetainUntilDate": "YYYY-MM-DDT00:00:00Z" 
}'