How to find out S3 Bucket last accessed time?

14,140

Solution 1

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.

Solution 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.

Resource Types Supported by CloudTrail API Activity History

Solution 3

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

Share:
14,140
upaang saxena
Author by

upaang saxena

I am a computer geek who learns each minute and loves scratching my head for stuffs. I date my laptop for almost 16 hours a day. You can find more information about me on my website

Updated on June 09, 2022

Comments

  • upaang saxena
    upaang saxena almost 2 years

    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.

    • upaang saxena
      upaang saxena almost 7 years
      Link for getting last modified time for the bucket: stackoverflow.com/questions/9679344/…
    • Yeshodhan Kulkarni
      Yeshodhan Kulkarni almost 7 years
      he can already get the LastModifiedTime or LastUpdatedTime, as per question.
  • upaang saxena
    upaang saxena almost 7 years
    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?
  • Yeshodhan Kulkarni
    Yeshodhan Kulkarni almost 7 years
    no. there is no api to find last accessed. you have to go through cloud trail as of now.
  • atline
    atline over 3 years
    Links 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.