use aws-cli to extend expiration and restart the delete or archive countdown on objects in an S3 bucket
Background
S3 buckets allow you to specify lifecycle rules that tell AWS to automatically delete or archive any objects in that bucket after a specific number of days. You can also specify a prefix with each rule so that different objects in the same bucket stay for different amounts of time.
Example 1: I created a bucket named
logs.example.com(not the real name) that automatically archives an object to AWS Glacier after it has been sitting in S3 for 90 days.
Example 2: I created a bucket named
tmp.example.com(not the real name) that automatically delete a file after it has been sitting there for 30 days.
This works great until you realize that there are specific files that you want to keep around for just a bit longer than its original expiration.
You could download and then upload the object to reset its creation date, thus starting the countdown from zero; but through a little experimentation, I found that one easy way to reset the creation/modification timestamp on an S3 object is to ask S3 to change the object storage method to the same storage method it currently has.
The following example uses the new aws-cli command line tool to reset the timestamp of an S3 object, thus restarting the lifecycle counter. This has an effect similar to the Linux/Unix touch command.