Skip to content

Object Lock bucket retention period

Estimated time to read: 2 minutes

On this page you can find information about setting up your bucket retention period with Object Lock.

Setting the retention period requires a bucket with Object Lock enabled. Enable Object Lock.

Object Lock object retention period object legal hold

Set a default bucket retention period

It is possible to set up a default bucket retention period. For example set up the bucket with GOVERNANCE mode and 30 days of retention.

aws s3api put-object-lock-configuration --bucket <bucket_name> \
    --object-lock-configuration '
{
    "ObjectLockEnabled": "Enabled",
    "Rule": {
        "DefaultRetention": {
            "Mode": "GOVERNANCE",
            "Days": 30
        }
    }
}'

The following options are available for setting up:

Option Choices Description
Mode GOVERNANCE Users with special permissions can update or delete
objects before the retention period ends.
COMPLIANCE No one can delete or modify objects until the retention
period expires. This restriction cannot be bypassed.
Time Days Enter the number of days for retention.
Years Enter the number of years for retention.

Get the default bucket retention period

Retrieve the current bucket Object Lock retention period with:

 aws s3api get-object-lock-configuration --bucket <bucket_name>
---
{
    "ObjectLockConfiguration": {
        "ObjectLockEnabled": "Enabled",
        "Rule": {
            "DefaultRetention": {
                "Mode": "GOVERNANCE",
                "Days": 30
            }
        }
    }
}

Disable default bucket retention period

It is possible to remove the default bucket retention period for new objects with:

aws s3api put-object-lock-configuration --bucket <bucket_name> \
    --object-lock-configuration '
{ 
    "ObjectLockEnabled": "Enabled" 
}'

New objects that are now created do not have a default bucket retention period.