upaang saxena
upaang saxena

Reputation: 789

How to find out S3 Bucket last accessed time?

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

Answers (4)

Aniket Kulkarni
Aniket Kulkarni

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

  1. S3 Server access logging provides detailed records of the requests that are made to objects in Amazon S3 buckets.
  2. 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.
  3. Each log record consists of information such as bucket name, the operation in the request, and the time at which the request was received.
  4. 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.

Upvotes: 0

Kashif Raza
Kashif Raza

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

Yeshodhan Kulkarni
Yeshodhan Kulkarni

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

vishal dutta
vishal dutta

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

Related Questions