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.
-
Link for getting last modified time for the bucket: http://stackoverflow.com/questions/9679344/how-can-i-get-last-modified-datetime-of-s3-objects-with-boto – upaang saxena May 20 '17 at 14:04
-
1he can already get the LastModifiedTime or LastUpdatedTime, as per question. – Yeshodhan Kulkarni May 20 '17 at 18:30
4 Answers
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.

- 21
- 2
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.

- 47
- 6

- 2,844
- 1
- 16
- 19
-
Yes, But then I think I need to parse the cloud trail logs and need to find the bucket from it. Is there any direct API from AWS regarding the same? – upaang saxena May 20 '17 at 20:47
-
2no. there is no api to find last accessed. you have to go through cloud trail as of now. – Yeshodhan Kulkarni May 20 '17 at 23:06
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

- 21
- 1
-
1Links to external resources are encouraged, but please add context around the link so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the external resource is unreachable or goes permanently offline. – atline Dec 15 '20 at 07:59
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
- S3 Server access logging provides detailed records of the requests that are made to objects in Amazon S3 buckets.
- Amazon S3 periodically collects access log records, consolidates the records in log files, and then uploads log files to your target bucket as log objects.
- Each log record consists of information such as bucket name, the operation in the request, and the time at which the request was received.
- S3 Server Access Log Format provides more details about the format of the log file.
You need to use the target bucket to get the required answer.

- 12,825
- 9
- 67
- 90