Question:
I want to upload and download files to S3 using boto3 without changing their “LastModified” date so I can keep tabs on the age of the contents. Whenever I upload or download a file it takes on the date of this operation and I lose the date that the contents were modified.
I’m looking at the timestamp of the files using
1 2 |
fileObj.get('LastModified') |
where the fileObj is taken from a paginator result. I’m using the following command to upload
1 2 |
s3Client.upload_fileobj(data, bucket_name, destpath) |
and the following to download the files:
1 2 |
s3Client.download_file(bucket_name, key, localPath) |
How can I stop the last modified date changing?
Answer:
This is not possible.
The Last Modified Date is generated by Amazon S3 and cannot be overridden.
If you wish to maintain your own timestamps, you could add some User-Define Metadata and set the value yourself.