Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Identifying and deleting S3 Objects that are not being accessed?

I have recently joined a company that uses S3 Buckets for various different projects within AWS. I want to identify and potentially delete S3 Objects that are not being accessed (read and write), in an effort to reduce the cost of S3 in my AWS account.

I read this, which helped me to some extent.

Is there a way to find out which objects are being accessed and which are not?

like image 906
Subbu Avatar asked Oct 24 '18 08:10

Subbu


Video Answer


2 Answers

There is no native way of doing this at the moment, so all the options are workarounds depending on your usecase.

You have a few options:

  1. Tag each S3 Object (e.g. 2018-10-24). First turn on Object Level Logging for your S3 bucket. Set up CloudWatch Events for CloudTrail. The Tag could then be updated by a Lambda Function which runs on a CloudWatch Event, which is fired on a Get event. Then create a function that runs on a Scheduled CloudWatch Event to delete all objects with a date tag prior to today.
  2. Query CloudTrail logs on, write a custom function to query the last access times from Object Level CloudTrail Logs. This could be done with Athena, or a direct query to S3.
  3. Create a Separate Index, in something like DynamoDB, which you update in your application on read activities.
  4. Use a Lifecycle Policy on the S3 Bucket / key prefix to archive or delete the objects after x days. This is based on upload time rather than last access time, so you could copy the object to itself to reset the timestamp and start the clock again.
like image 185
Matt D Avatar answered Sep 20 '22 02:09

Matt D


No objects in Amazon S3 are required by other AWS services, but you might have configured services to use the files.

For example, you might be serving content through Amazon CloudFront, providing templates for AWS CloudFormation or transcoding videos that are stored in Amazon S3.

If you didn't create the files and you aren't knowingly using the files, can you probably delete them. But you would be the only person who would know whether they are necessary.

like image 22
John Rotenstein Avatar answered Sep 20 '22 02:09

John Rotenstein