I set a lifecycle configuration rule on my Amazon Simple Storage Service (Amazon S3) bucket to transition objects to another storage class, or expire or delete objects. However, the objects didn't change according to the rule. I need to confirm that the rule is working to manage costs or for compliance.
Resolution
An S3 lifecycle action is asynchronous. Asynchronous actions can delay the removal of an object past the expiration or transition date in a lifecycle configuration rule. However, after you meet the conditions of the lifecycle rule, AWS changes the billing, even when the action isn't complete.
S3 lifecycle rules run only once each day at midnight UTC. Also, Amazon S3 rounds the transition or expiration date of an object to midnight UTC the next day. For example, you create an object on 1/1/2020 10:30 UTC with a lifecycle rule to transition the object after 3 days. So, the transition date is 1/5/2020 00:00 UTC.
Before you check whether a lifecycle rule is complete, verify that enough time elapsed. If enough time elapsed and your lifecycle rule isn't complete, then check that you correctly set the prefix filter for objects on the lifecycle rule.
Prefix filters determine the objects that the lifecycle rule affects. For example, if you specify a prefix filter as images/, then the lifecycle rule applies only to objects under the prefix images/.
Note: Be sure to specify the / character at the end of the prefix filter. If you specify the / character at the beginning of the prefix filter, then Amazon S3 doesn't correctly evaluate the lifecycle rule.
You can use the HeadObject API, the AWS Command Line Interface (AWS CLI), or the Amazon S3 console to check when a current version object is scheduled to expire.
Note: If you receive errors when you run AWS CLI commands, then see Troubleshooting errors for the AWS CLI. Also, make sure that you're using the most recent AWS CLI version.
Use the AWS CLI
Run the following AWS CLI head-object command to know when the object expires:
aws s3api head-object --bucket bucketname --key file.txt
Example output:
{
"AcceptRanges": "bytes",
"Expiration": "expiry-date=\"Wed, 15 Mar 2023 00:00:00 GMT\", rule-id=\"MyExpirationRule\"",
"LastModified": "2023-02-22T17:20:34+00:00",
"ContentLength": 6,
"ETag": "\"edae42exa0d2b93b123346740107dacf\"",
"VersionId": "SoshCRUrlabc1v4ZzYEA123PvWcaeF6F",
"ContentType": "text/plain",
"ServerSideEncryption": "AES256",
"Metadata": {}
}
The Expiration response header provides the expiry-date and rule-id. The expiry-date field shows the date when Amazon S3 queues the object for removal and asynchronously removes the object. The rule-id field shows the lifecycle rule that you applied to the object.
Use the Amazon S3 console
Complete the following steps:
- Open the Amazon S3 console.
- On the Buckets list, select the name of your bucket.
- Select the name of the object that you want to check.
- Choose the Properties tab.
- In the Object Management Overview section, under Management Configurations, review the Expiration rule and Expiration date fields.
The Expiration date field shows the date when Amazon S3 queues the object for removal and asynchronously removes the object. The Expiration rule field shows the lifecycle rule that you applied to the object.
Note: Only current version objects return the Expiration response header for HEAD or GET requests. Previous versions and delete markers don't return the response header. Also, there's no specific response header to check the transition date for objects that are eligible for transitions.
Related information
Setting an S3 Lifecycle configuration on a bucket
How do I monitor the actions taken by my lifecycle rules?