Reputation: 789
I have a use-case where I need to find out last accessed time of the S3 bucket, but I am not able to find a way to do so. Though, we can get LastModifiedTime or LastUpdatedTime for the bucket, but I couldn't find any AWS API, which can give me the last accessed time for the AWS S3 Bucket. One way to do this is to parse through all the objects inside the buckets, but that's a very expensive operation to do, which I can't afford. Can somebody help me in getting the LastAccessedTime for the AWS S3 Bucket? I am using Python with boto3.
Upvotes: 9
Views: 31460
Reputation: 12993
I don't have a code ready to post as an answer but I have an approach by using which you can achieve it.
You can utilize the Amazon S3 server access logging
You need to use the target bucket to get the required answer.
Upvotes: 0
Reputation: 21
I know it is too late but it can help for other people We can use Bucket Metrics to see details for our S3 bucket utilization.
https://docs.aws.amazon.com/AmazonS3/latest/user-guide/configure-metrics.html
Upvotes: 1
Reputation: 2943
You can use AWS Cloud Trail to find the last access to a resource based on resource type.
See the below document from AWS which enables query based on resource type, in your case an S3 bucket.
Resource Types Supported by CloudTrail API Activity History
Upvotes: 1
Reputation: 21
Even I am facing the same problem. I need to access the last process time for objects present in my S3 bucket to fetch the objects which are good candidates to be moved to S3 storage class. Unfortunately I couldn't find a direct way to fetch that time.
As a work around what you can do is setup AWS Cloudtrail at Object Level
Now you can go through these logs and look for "GetObject" event under "eventName" key along with time of event under "eventTime" key.
I know this is not an optimize solution. But I couldn't find any other way to achieve it. If anyone has a better solution please share.
Upvotes: 2