# DeleteBucketLifecycle

DeleteBucketLifecycle removes a bucket's lifecycle configuration - every rule in it, in one
call. From then on, objects no longer expire, noncurrent versions are no longer removed and
incomplete multipart uploads are no longer aborted on the basis of the deleted rules. Removing
the last rule in the dashboard and saving does exactly the same. To change or remove only some
rules, [PutBucketLifecycleConfiguration](https://docs.strg.com/s3-api/PutBucketLifecycleConfiguration) takes the full
set you want to keep. [Lifecycle policies](https://docs.strg.com/lifecycle-policies) explains what the rules do.

**Info: Good to know on STRG**

- `x-amz-expected-bucket-owner` is welcome and has nothing to check: a key only ever reaches
  buckets of its own account.
- The configuration belongs to the whole bucket, so an access key limited to a key prefix can
  still delete all of it.
- A bucket in another region answers `404 NoSuchBucket` rather than a redirect; the bucket's own
  regional endpoint reaches it.

**Warning: Versions stay billed**

Every bucket keeps all versions of its objects. Without a lifecycle rule that removes noncurrent
versions, every version is billed as stored data until it is deleted.
[Keeping 30 days of old versions](https://docs.strg.com/lifecycle-policies#keeping-30-days-of-old-versions)
shows a rule that keeps this in check.

## When you'd use it

- **Keeping everything for a while.** A team asked to preserve every old version for an audit
  can take the rules off a bucket in one call, and nothing is tidied away until new rules are
  put back.
- **Retiring a temporary setup.** A bucket that once held scratch data under `tmp/`, with a rule
  expiring it after a few days, now holds data worth keeping; deleting the configuration stops
  the expiry.
- **Settings kept in code.** A deploy script that manages each bucket's settings can return a
  bucket to having no rules at all with this one call, the same way the dashboard does when its
  last rule is removed.

## Request

```http
DELETE /?lifecycle HTTP/1.1
Host: my-bucket.s3.eu-central-1.strg.com
Authorization: AWS4-HMAC-SHA256 Credential=...
x-amz-date: 20260926T120000Z
x-amz-content-sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
```

Path-style, the same request is `DELETE /my-bucket?lifecycle` on `s3.eu-central-1.strg.com`.
[Addressing](https://docs.strg.com/s3-api/overview#addressing) in the S3 API overview has both styles.

### Permissions

The access key needs **Manage lifecycle rules** (`bucket-lifecycle:write`). A key limited to
certain buckets works too, as long as this bucket is one of them. A key prefix does not narrow
this operation, because the configuration belongs to the whole bucket.
[Access keys](https://docs.strg.com/access-keys) has every permission.

### URI parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Bucket` | String | Yes | The bucket whose lifecycle configuration is deleted. |
| `lifecycle` | Flag | Yes | Selects the lifecycle subresource. Sent without a value. |

STRG answers `501 NotImplemented` to any other query parameter, so a client knows straight
away. The `X-Amz-*` parameters of a presigned URL and the `x-id` parameter the JavaScript SDK
adds are welcome.

### Request headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `x-amz-expected-bucket-owner` | String | No | Welcome, with nothing to check: an access key only ever reaches its own account's buckets. |

### Request body

None.

## Response

A successful delete answers `204 No Content` with no body. After it,
[GetBucketLifecycleConfiguration](https://docs.strg.com/s3-api/GetBucketLifecycleConfiguration) answers
`404 NoSuchLifecycleConfiguration`.

### Response headers

| Name | Description |
| --- | --- |
| `x-amz-request-id` | The request ID, useful in a support request. |

### Response body

None.

## Errors

These are the answers a client can get instead of `204`, and the situation behind each.

| Code | HTTP status | When |
| --- | --- | --- |
| `NoSuchBucket` | 404 | The bucket does not exist, it is in a region other than the endpoint's, or the account stores nothing in this endpoint's region yet. |
| `AccessDenied` | 403 | The access key does not hold **Manage lifecycle rules**, or the bucket is outside its scope. |
| `InvalidAccessKeyId` | 403 | The access key does not exist, has expired or has been revoked - or it was created moments ago and is not yet usable in this region, where the account already stores data. A retry a moment later succeeds. |
| `SignatureDoesNotMatch` | 403 | The request signature does not match. |
| `RequestTimeTooSkewed` | 403 | The request time is more than 15 minutes from the server's. |
| `AuthorizationHeaderMalformed` | 400 | The signature's credential scope names a region other than the endpoint's. |
| `NotImplemented` | 501 | The request carries a query parameter this operation does not take. |
| `SlowDown` | 503 | Too many requests at once. A retry after the `Retry-After` interval goes through. |
| `ServiceUnavailable` | 503 | A temporary failure. A retry of the same request is safe. |

## Differences from Amazon S3

| Aspect | Amazon S3 | STRG |
| --- | --- | --- |
| Bucket in another region | `301` redirect with `x-amz-bucket-region` | `404 NoSuchBucket`. The bucket's own regional endpoint reaches it. |
| `x-amz-expected-bucket-owner` | Checked against the bucket owner | Welcome, with nothing to check: a key only reaches its own account's buckets |

## Examples

Removing every lifecycle rule from `my-bucket`:

**AWS CLI**

```bash
aws s3api delete-bucket-lifecycle \
  --bucket my-bucket \
  --endpoint-url https://s3.eu-central-1.strg.com \
  --region eu-central-1
```

**Python (boto3)**

```python
import boto3

s3 = boto3.client(
    "s3",
    endpoint_url="https://s3.eu-central-1.strg.com",
    region_name="eu-central-1",
)

s3.delete_bucket_lifecycle(Bucket="my-bucket")
```

**JavaScript (AWS SDK v3)**

```javascript
import { DeleteBucketLifecycleCommand, S3Client } from "@aws-sdk/client-s3";

const client = new S3Client({
  endpoint: "https://s3.eu-central-1.strg.com",
  region: "eu-central-1",
});

await client.send(new DeleteBucketLifecycleCommand({ Bucket: "my-bucket" }));
```

## Related

- [PutBucketLifecycleConfiguration](https://docs.strg.com/s3-api/PutBucketLifecycleConfiguration)
- [GetBucketLifecycleConfiguration](https://docs.strg.com/s3-api/GetBucketLifecycleConfiguration)
- [Lifecycle policies](https://docs.strg.com/lifecycle-policies)
- [Access keys](https://docs.strg.com/access-keys)
- [S3 API overview](https://docs.strg.com/s3-api/overview)
