Skip to content

Why isn't the lifecycle rule on my Amazon S3 bucket working even though I applied it more than one day ago?

4 minute read
1

I set a lifecycle configuration rule on my Amazon Simple Storage Service (Amazon S3) bucket. It transitions objects to another storage class, or expires or deletes 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.

Short description

An Amazon 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.

Amazon S3 lifecycle rules run only once each day. Also, Amazon S3 rounds the transition or expiration date of an object to midnight UTC the next day. 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.

Resolution

Note: If you receive errors when you run AWS Command Line Interface (AWS CLI) commands, then see Troubleshooting errors for the AWS CLI. Also, make sure that you're using the most recent AWS CLI version.

You can use the HeadObject API, the AWS Command Line Interface (AWS CLI), or the Amazon S3 console to know when a current version of an object expires.

Note: The header is available only for current object versions, not for non-current objects or delete markers. If you request or show versions, then Amazon S3 doesn't return a headobject response. When you send a headobject request with the AWS CLI or AWS API, don't include the VersionID in the request. When you use the console, don't turn on Show versions.

Note: There's no specific response header to check the transition date for objects that are eligible for transitions.

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

Note: Replace bucketname with the name of your bucket and replace file.txt with your key value.

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:

  1. Open the Amazon S3 console.
  2. On the Buckets list, select the name of your bucket.
  3. Select the name of the object that you want to check.
  4. Choose the Properties tab.
  5. 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 Expires 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?

AWS OFFICIALUpdated 2 months ago