What is a lifecycle policy?
A lifecycle policy is a file written in XML (or JSON) format that contains rules for automating the movement of objects from one stage of their lifecycle to another. The movement is typically based on the “age” and size of the object, as well as other parameters. You can find more information on the different parameters in the Amazon documentation. There are several ways to utilize a Lifecycle Policy. Gcore supports a lifecycle policy, which allows you to set an expiration time for an object and automatically remove it from the bucket once the expiration time is reached.Lifecycle policy logic
Object deletion is processed around midnight UTC. The table below shows when an object is deleted based on the scenario.
The midnight UTC processing window means deletion happens at the next processing cycle after the expiration period ends — not at the exact moment the period expires.
Gcore lifecycle configuration elements
Here is an example of a completed XML file with the lifecycle policy:<Rule>...</Rule>.This section includes all the settings below.<ID>...</ID>.Specify a unique identifier for the rule. The ID can be up to 255 characters long and include numbers, Latin letters, and underscores.<Prefix/>.Leave the tag empty if you want to apply the rule to the entire bucket or specify the folder’s name.<Status>...</Status>.Specify either “Enabled” or “Disabled”. If a rule is in the “Disabled” status, no actions specified in the rule will be performed.<Expiration><Days>...</Days></Expiration>.Specify the days you want the object to be kept in your bucket in the “Expiration” section.
Manage a lifecycle policy with AWS CLI
Add a lifecycle policy to your bucket
1. Create an XML file:IDisone_day.- The rule is applied to the entire bucket (
<Prefix/>). - The rule is active (status is
Enabled). - The file expiration time is 1 day.
"Prefix": "") applies the Lifecycle Configuration to the entire bucket. Specify the folder name if you need to apply the policy to a specific folder in the bucket. For example, if the objects are in the deleteme folder, the value will be "Prefix": "deleteme /".
3. Save the file as lifecycle.json.
4. Start the AWS CLI from the directory with the lifecycle.json file and run the following command:
my_bucketname in the example with your bucket name.https://luxembourg-2.storage.gcore.devwith your storage endpoint. To choose the correct value for this parameter, use the “S3 service URLs and default region names” guide.
my_bucketname in the example with your bucket name.https://luxembourg-2.storage.gcore.devwith your storage endpoint. To choose the correct value for this parameter, use the “S3 service URLs and default region names” guide.
Delete a lifecycle policy
To delete the policy from the bucket, use the following command:my_bucketname in the example with your bucket name.https://luxembourg-2.storage.gcore.devwith your storage endpoint. To choose the correct value for this parameter, use the “S3 service URLs and default region names” guide.