> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://wiki.leviia.com/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# Implementation of S3 LifeCycles

To implement lifecycles on your buckets, we recommend using a command prompt with S3 CLI.

Lifecycles are applied to buckets via a CLI command and a local file in “.JSON” format.

This file must be locally present on your machine.

The CLI command will “read” the Lifecycle file (JSON) on your machine and apply this information to your bucket.

__The JSON file must not be dropped into the bucket, as this is pointless.__

In the example below :
* the file is called `lifecycle-policy.json`.
* the bucket concerned is `BUCKET_NAME`.
* the Leviia endpoint is `s3.eu-west.leviia.com`.

### Apply a Lifecycle Configuration

```
aws s3api put-bucket-lifecycle-configuration --bucket BUCKET_NAME --lifecycle-configuration file://lifecycle-policy.json --endpoint-url https://s3.eu-west.leviia.com/
```

### Retrieve/display Current Lifecycle Configuration

```
aws s3api get-bucket-lifecycle-configuration --bucket BUCKET_NAME --endpoint-url https://s3.eu-west.leviia.com/
```

### Delete a Lifecycle Configuration

```
aws s3api delete-bucket-lifecycle --bucket BUCKET_NAME --endpoint-url https://s3.eu-west.leviia.com/
```

Warning: this deletes *all* bucket lifecycle rules.

**Important notes :**

1. Lifecycle rules are executed asynchronously, so there may be a delay between configuration and actual application.

2. To test your rules, we recommend that you first apply the configuration to a test bucket before using it in production.

3. Objects protected by S3 Object Lock (immutability) will not be deleted by lifecycle rules before the end of their retention period.
---

###### Other tutorials on S3 Lifecycles :

[Understanding S3 Lifecycles](https://wiki.leviia.com/en/article/understanding-s3-lifecycles-and-related-concepts-1i9cayh/)
[Setting S3 Lifecycles](https://wiki.leviia.com/en/article/setting-up-s3-lifecycles-w3nfum/)

