Charlie
Charlie

Reputation: 1746

Delete S3 Bucket if inactive for set amount of time?

Is there a way to configure a S3 bucket to be deleted if it hasn't been updated in a set amount of time?

Basically want a bucket to be deleted if it hasn't had any new uploads to it within a set amount of time.

Upvotes: 2

Views: 831

Answers (1)

John Rotenstein
John Rotenstein

Reputation: 269101

There is no in-built capability to do this.

One method of achieving it would be:

  • Configure an Event on the bucket to trigger an AWS Lambda function whenever there is an upload
  • The Lambda function stores a timestamp in the bucket metadata
  • Use Amazon CloudWatch Events to trigger a scheduled event every week (or as desired) to trigger another Lambda function that checks the timestamp on the bucket (or multiple buckets). If the timestamp is more than n days old, the Lambda function deletes the bucket.

Alternatively...

Are you sure you wish to actually delete a bucket? I presume you have certain 'users' who each have a bucket. Instead of giving each user a bucket, you could:

This is much more scalable than "one bucket per user" because there are limitations on the number of buckets per account, but no limits on the number of directories or objects in one bucket.

Upvotes: 3

Related Questions