Skip to main content

Object Lock

Object Lock stops object versions from being overwritten or deleted until a date you choose. This is often called WORM (write once, read many). Use it for backups that must survive ransomware, a compromised server or a mistake, and for records you're required to keep unchanged for a set time.

Object Storage uses the same Object Lock API as Amazon S3, so tools that support S3 Object Lock work with it.

:::info API only Object Lock is set up with the S3 API. The web panel has no Object Lock settings. See Using the S3 API for setup. :::

Key ideas​

  • Object Lock protects versions. It needs versioning, which is turned on automatically when you create a bucket with Object Lock.
  • Object Lock must be turned on when you create the bucket.
  • A lock is either a retention period (until a date) or a legal hold (until someone removes it). A version can have both.

Retention modes​

GovernanceCompliance
Protects againstOrdinary users and applicationsEveryone
Can the lock be shortened or removed early?Yes, by users with special permissionNo. It can only be extended.
Good forTesting your setup, internal safeguardsBackups and records that must not be deleted

Start with a short Compliance period, such as 1 day, to test your setup. A Compliance lock can't be undone, and the locked data is billed until the lock ends.

Create a bucket with Object Lock​

cd ~
aws s3api create-bucket --bucket <bucket> --object-lock-enabled-for-bucket --profile bamboozle

Check it:

cd ~
aws s3api get-object-lock-configuration --bucket <bucket> --profile bamboozle

Set a default retention​

A default retention locks every new object version automatically, so your backup tool doesn't need to know about Object Lock. This example locks each new version for 30 days in Compliance mode:

cd ~
aws s3api put-object-lock-configuration --bucket <bucket> --profile bamboozle \
--object-lock-configuration '{"ObjectLockEnabled":"Enabled","Rule":{"DefaultRetention":{"Mode":"COMPLIANCE","Days":30}}}'

Use "Years" instead of "Days" for long periods. A default retention only applies to versions written after you set it.

Lock a single object​

Set the retention while uploading:

cd ~
aws s3api put-object --bucket <bucket> --key contracts/2026-001.pdf --body 2026-001.pdf \
--object-lock-mode COMPLIANCE --object-lock-retain-until-date 2033-12-31T00:00:00Z \
--profile bamboozle

Or lock an object that's already there:

cd ~
aws s3api put-object-retention --bucket <bucket> --key contracts/2026-001.pdf \
--retention '{"Mode":"COMPLIANCE","RetainUntilDate":"2033-12-31T00:00:00Z"}' --profile bamboozle

Check an object's lock:

cd ~
aws s3api get-object-retention --bucket <bucket> --key contracts/2026-001.pdf --profile bamboozle

Add --version-id <version-id> to work on a specific version instead of the latest one.

A legal hold locks a version with no end date until it's removed, for example during a dispute or an investigation. It works independently of retention.

cd ~
# Place a hold
aws s3api put-object-legal-hold --bucket <bucket> --key contracts/2026-001.pdf \
--legal-hold Status=ON --profile bamboozle

# Release it
aws s3api put-object-legal-hold --bucket <bucket> --key contracts/2026-001.pdf \
--legal-hold Status=OFF --profile bamboozle

What happens when you delete​

ActionResult
Delete an object without a version IDAllowed. A delete marker is added and the object disappears from listings. The locked version is kept and can be restored.
Delete a locked version (with its version ID)Refused with AccessDenied until the retention date has passed and any legal hold is removed
Overwrite an objectAllowed. A new version is created. The locked version is kept.
Delete the bucketNot possible while it contains versions

After the retention date, the version is no longer protected, but it isn't deleted automatically. Use a lifecycle rule to clean up old versions once their lock has expired.

Plan your retention period​

  • Locked versions are billed until the lock ends and you delete them. Long periods on frequently changing data add up quickly.
  • Match the period to your backup scheme. For example, with daily backups and 30-day retention, any backup can be restored for at least 30 days, even if your backup server and its keys are compromised.
  • For a complete backup setup with Object Lock, see the backup target guide.
Was this page helpful?