Managing Object Lifecycle
When using S3, you may need to manage the lifecycle of objects to optimize resource usage and prevent storage overflow. To achieve this, you can configure lifecycle rules, which automatically delete objects after a specified number of days.
Here’s how to set up lifecycle rules for objects in an S3 bucket using the Hostman control panel and the AWS CLI.
Via the Control Panel Copy link
Creating Rules Copy link
To create lifecycle rules:
- Go to the S3 Storage section and click on the bucket.
- In the Settings tab, click Change next to Lifecycle.

- Click Add rule.
- Set up the parameters:
-
- Object prefix. For example, if you set the prefix
logs/, the rule will only apply to objects in thelogs“folder.” - Action. Choose what should happen to the objects and after how many days the action should be applied. Three options are available:
- Delete any: applies to any object in the bucket.
- Delete non-current: applies to old versions of objects (relevant if object versioning is enabled).
- Abort incomplete upload: automatically removes unfinished multipart uploads.
- Object prefix. For example, if you set the prefix
-
Click Save.

Managing Existing Rules Copy link
To view and manage all existing lifecycle rules:
- Go to the S3 Storage section and click on the bucket.
- In the Settings tab, click Change next to Lifecycle.
The window will display all existing rules, including those added through external tools such as the AWS CLI.
Here, you can:
- Delete a rule by clicking the trash bin icon.
- Temporarily disable a rule by toggling the switch.
- Edit a rule by clicking on it to open the edit window.

Via AWS CLI Copy link
Creating a Lifecycle Rule File Copy link
To set up automatic deletion of files after a certain period, create a configuration file for the lifecycle rules. For example, if you want to store files in the logs folder for only one day, create a file named lifecycle.json with the following content:
{
"Rules": [
{
"Status": "Enabled",
"Filter": {"Prefix": "logs/"},
"Expiration": {"Days": 1}
}
]
}
-
Prefix: Specifies the folder (or prefix) to which the rule will apply. In this example, files in thelogs/folder will be automatically deleted after one day. -
Expiration: Defines the retention period in days. Here, files are deleted one day after upload.
Adding Multiple Rules Copy link
You can add multiple rules for different folders or files. For instance, if you have another folder, logs2, where files should be stored for two days, simply add an additional rule:
{
"Rules": [
{
"Status": "Enabled",
"Filter": {"Prefix": "logs/"},
"Expiration": {"Days": 1}
},
{
"Status": "Enabled",
"Filter": {"Prefix": "logs2/"},
"Expiration": {"Days": 2}
}
]
}
With this configuration:
- Files in the
logs/folder will be retained for one day. - Files in the
logs2/folder will be retained for two days.
Uploading Lifecycle Rules to a Bucket Copy link
After creating the lifecycle rule file, upload it to your S3 bucket using the following command:
aws s3api put-bucket-lifecycle-configuration --bucket <bucket_name> --lifecycle-configuration file://lifecycle.json --endpoint-url https://s3.hmstorage.netThis command applies the specified rules to your bucket, and files will be automatically deleted after the defined period.
Verifying Lifecycle Rules Copy link
To ensure that the lifecycle rules were successfully applied, run the following command:
aws s3api get-bucket-lifecycle-configuration --bucket <bucket_name> --endpoint-url https://s3.hmstorage.netThis will display the current lifecycle rules configured for your bucket.
Removing Lifecycle Rules Copy link
If you need to delete all existing lifecycle rules for a bucket, execute the following command:
aws s3api delete-bucket-lifecycle --bucket <bucket_name> --endpoint-url https://s3.hmstorage.netThis command removes all lifecycle rules, and files will no longer be automatically deleted.