Lifecycle policy logic
Object removal runs around midnight UTC. Three conditions govern deletion timing:- Lifecycle policy set before upload. If the policy is set for 1 day and the object is uploaded on January 2, it is removed on January 4.
- Lifecycle policy set after upload. If an object is uploaded on January 1 (at any time) and a 1-day expiration policy is then applied, the object is deleted on January 3.
- Lifecycle policy removed. Deleting the lifecycle policy from the bucket stops automatic removal — objects already in the bucket are kept.
Lifecycle configuration elements
AWS CLI uses a JSON configuration file. The file structure is:AWS CLI lifecycle management
AWS CLI provides three commands for managing lifecycle policies:put-bucket-lifecycle to apply a policy, get-bucket-lifecycle-configuration to verify it, and delete-bucket-lifecycle to remove it.
Applying a lifecycle policy
1
Create the configuration file
Create a
lifecycle.json file with the following content:To apply the rule to a specific folder, set
"Prefix" to the folder name: "Prefix": "deleteme/".2
Apply the policy
Run the following command from the directory containing
lifecycle.json, replacing the placeholder values:3
Verify the configuration
Run the following command to check the current lifecycle configuration:The response contains the applied policy as JSON.