AWS EFS - lifecycle rule to delete old files

Viewed 4090

I'm using EFS

I want to set up some form of lifecycle rule to delete all files that are in the EFS for over 10 days (or preferably, but not necessary, if they were not accessed for 10 days)

From the configuration, it seems not to be possible. Is there some way to do that? Maybe using some lambda or something else?

2 Answers

Move to IA then delete

You can use the following:

Enables lifecycle management by creating a new LifecycleConfiguration object. A LifecycleConfiguration object defines when files in an Amazon EFS file system are automatically transitioned to the lower-cost EFS Infrequent Access (IA) storage class. A LifecycleConfiguration applies to all files in a file system

  put-lifecycle-configuration
--file-system-id <value>
--lifecycle-policies <value>
[--cli-input-json <value>]
[--generate-cli-skeleton <value>]

Just delete

But this is still a bit pricy and will still require you to delete manually EFS IA storage class.

So I would use a cron tasks where you retrieve your files creation date everyday and then automatically delete those above the threshold using the AWS CLI.

There is no way to do this with a lifecycle currently.

You can use:

  1. AWS Lambda function
  2. Connect/mount EFS
  3. Execute a script with the desired actions (list and delete files).

I would use a simple script to do my job. You can follow the guides here and the repo here

Related