---
title: PutObjectLockConfiguration · S3 API
description: Turns on object lock, and sets the default retention for new versions.
doc_version: 0.1.0-preview
last_updated: 2026-09-14
---

# PutObjectLockConfiguration

`PUT /{bucket}?object-lock`

Turns on object lock, and sets the default retention for new versions.

Object lock keeps each retained version until its retain-until date. Nobody can delete the version or shorten the date before then. This call also turns on versioning.

- Role: Editor or higher.
- Support: partial.
- Auth: AWS Signature Version 4 with your API key. See [S3 API](/api/s3.md).
- COMPLIANCE mode with a default in days. Years, GOVERNANCE, and legal hold return 501.
- Without Rule, object lock is on and new versions get no default retention.

## Example request

```http
PUT /support-tickets?object-lock HTTP/1.1
Host: wspq7ws2np5l8z4.storage.beta.graphon.sh
x-amz-date: 20261007T093000Z
x-amz-content-sha256: be1d386947f4b964967aa4630b0d590afad147a465c9a88adf8c80b44335b12a
Authorization: AWS4-HMAC-SHA256 Credential=<ACCESS_KEY_ID>/20261007/us-east-1/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=<SIGNATURE>
Content-Length: 267

<ObjectLockConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
  <ObjectLockEnabled>Enabled</ObjectLockEnabled>
  <Rule>
    <DefaultRetention>
      <Mode>COMPLIANCE</Mode>
      <Days>30</Days>
    </DefaultRetention>
  </Rule>
</ObjectLockConfiguration>
```

## Path parameters

- `bucket` (string, required): The bucket name.

## Query parameters

- `object-lock` (flag, required): Selects this operation. Send it with no value.

## Headers

- `x-amz-expected-bucket-owner` (string, optional): The workspace ID that must own the bucket. Another owner returns `403 AccessDenied`.

## Request body

- `ObjectLockConfiguration` (object, required): The root element.
  - `ObjectLockEnabled` (string, required): Send `Enabled`.
  - `Rule.DefaultRetention` (object, optional): The default retention for new versions.
    - `Mode` (string, required): Send `COMPLIANCE`. Storage supports no other mode.
    - `Days` (integer, required): How many days to retain each new version.

## Responses

### 200 · OK

Storage saved the settings.

```http
HTTP/1.1 200 OK
x-amz-request-id: 4F8A2C7D1E6B4093A5C2D8E1F7B3A960
```

## Errors

Any request can also get the common errors on [S3 API](/api/s3.md).

### 501 · `NotImplemented`

The body uses Years, GOVERNANCE mode, or legal hold.

Send COMPLIANCE mode with Days.

### 404 · `NoSuchBucket`

No bucket has this name, or the bucket was deleted.

Check the bucket name. ListBuckets shows the buckets of the workspace.

### 403 · `AccessDenied`

The key does not have the role for this operation, or the bucket is in another workspace.

Use a key of the workspace that owns the bucket, with the role above.

## Other request languages

### aws CLI

```bash
# The graphon profile from the S3 API overview.
export AWS_PROFILE=graphon

aws s3api put-object-lock-configuration \
  --bucket support-tickets \
  --object-lock-configuration '{"ObjectLockEnabled":"Enabled","Rule":{"DefaultRetention":{"Mode":"COMPLIANCE","Days":30}}}'
```

### Python (boto3)

```python
# Replace wspq7ws2np5l8z4 with your workspace ID.
import os

import boto3
from botocore.config import Config

api_key = os.environ["GRAPHON_API_KEY"]
access_key_id = api_key.split("_", 1)[1].split(".")[0]

s3 = boto3.client(
    "s3",
    endpoint_url="https://wspq7ws2np5l8z4.storage.beta.graphon.sh",
    region_name="us-east-1",
    aws_access_key_id=access_key_id,
    aws_secret_access_key=api_key,
    config=Config(signature_version="s3v4", s3={"addressing_style": "path"}),
)

response = s3.put_object_lock_configuration(
    Bucket="support-tickets",
    ObjectLockConfiguration={
        "ObjectLockEnabled": "Enabled",
        "Rule": {
            "DefaultRetention": {
                "Mode": "COMPLIANCE",
                "Days": 30,
            },
        },
    },
)
print(response["ResponseMetadata"]["HTTPStatusCode"])
```

### JavaScript (AWS SDK)

```javascript
// Replace wspq7ws2np5l8z4 with your workspace ID.
import { S3Client, PutObjectLockConfigurationCommand } from '@aws-sdk/client-s3';

const apiKey = process.env.GRAPHON_API_KEY;
if (!apiKey) throw new Error('Set GRAPHON_API_KEY.');
const accessKeyId = apiKey.split('_')[1].split('.')[0];

const s3 = new S3Client({
  endpoint: 'https://wspq7ws2np5l8z4.storage.beta.graphon.sh',
  region: 'us-east-1',
  forcePathStyle: true,
  credentials: { accessKeyId, secretAccessKey: apiKey },
});

const response = await s3.send(new PutObjectLockConfigurationCommand({
  Bucket: 'support-tickets',
  ObjectLockConfiguration: {
    ObjectLockEnabled: 'Enabled',
    Rule: {
      DefaultRetention: {
        Mode: 'COMPLIANCE',
        Days: 30,
      },
    },
  },
}));
console.log(response.$metadata.httpStatusCode);
```

## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
