I would like to know how to EXTEND a key's expiration. I am not referring to the signed URL that accesses the object but the key itself.
I setup AWS to have a rule that all objects within the bucket should expire in 90 days. This is what I want to happen in most cases. Now and then I need to extend an individual key's lifetime by up to an additional 90 days. In fact resetting the countdown is fine.
I have tried this using the AWS SDK to no avail.
My First attempt was to alter metadata using copyObject:
ObjectMetadata meta = s3client.getObjectMetadata( bucket, key );
meta.setExpirationTime( getFutureDate( 90*DAYS ) );
CopyObjectRequest copyObjectRequest = new CopyObjectRequest( bucket, key, bucket, key );
copyObjectRequest.setNewObjectMetadata( meta );
copyObjectRequest.setStorageClass( StorageClass.Standard );
s3client.copyObject( copyObjectRequest );
The above did not work. The JavaDoc even clued me in as to why (read it after attempting).
void com.amazonaws.services.s3.model.ObjectMetadata.setExpirationTime(Date expirationTime)
For internal use only. This will *not* set the object's expiration time, and is only used to set the value in the object after receiving the value in a response from S3.
I then tried a variation on the above based on this link (added setStorageClass): https://alestic.com/2013/09/s3-lifecycle-extend/
Any help is appreciated.
It would appear that you are trying to achieve the following:
As per the alestic blog post you referenced, this can be done by copying the object on top of itself. In fact, it doesn't even seem to need the change of storage class.
I uploaded an object to a bucket, then ran this Python code:
import boto
conn = boto.s3.connect_to_region('ap-southeast-2')
mybucket = conn.get_bucket('BUCKET-NAME')
mybucket.copy_key('OBJECT-NAME', 'BUCKET-NAME', 'OBJECT-NAME')
This code copied the object "to itself" and the Management Console showed a new last modified date. I did not test the lifecycle rule, but I would assume this is the date used to determine the start of the 90-day period.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With