Does S3 bucket has information in regard to when is the last time it has been updated? How can I find the last time any of the objects in the bucket were updated?
Amazon S3 Object Expiration Overview The prefix (e.g. "logs/") identifies the object(s) subject to the expiration rule, and the expiration period specifies the number of days from creation date (i.e. age) after which object(s) should be removed.
Resolution. Most objects replicate within 15 minutes. However, sometimes replication can take a couple of hours. In rare cases, the replication can take longer.
Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . In the Buckets list, choose the name of the bucket that you want to view the properties for. Choose Properties. On the Properties page, you can configure the following properties for the bucket.
As others have commented, there's no magic bit of metadata that stores this information. You just have to loop over the objects.
Code to do that with boto3
:
import boto3
from datetime import datetime
def bucket_last_modified(bucket_name: str) -> datetime:
"""
Given an S3 bucket, returns the last time that any of its objects was
modified, as a timezone-aware datetime.
"""
s3 = boto3.resource('s3')
bucket = s3.Bucket(bucket_name)
objects = list(bucket.objects.all())
return max(obj.last_modified for obj in objects)
There is no native support for bucket last modified time
. The way I do it is to use aws cli
, sort the output, take the bottom line and print the first 2 fields.
$ aws s3 ls mybucket --recursive | sort | tail -n 1 | cut -d ' ' -f1,2
2016-03-18 22:46:48
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