Skip to main content

Auto-delete renders

available from v4.0.32

To automatically delete renders and associated files after some time, you need to:

1
Enable the lifecycle rules on the AWS bucket.
2
Render a video with the deleteAfter option.

Apply the lifecycle rules

1
Ensure the right permission

To put a lifecycle rule on the bucket, you need to have the s3:PutLifecycleConfiguration permission for your user.

  • If you set up Remotion Lambda after 4.0.32, you have it automatically.
  • If you set up Remotion Lambda previously, execute the following:
    1. Upgrade to at least Remotion 4.0.32.
    2. Click here to go to the users section in the AWS console.
    3. Select your user.
    4. Under "Permissions policies", click your policy (underlined in blue)
    5. Choose the "JSON" mode for editing.
    6. Under the "Sid": "Storage" section, add "s3:PutLifecycleConfiguration" to the "Action" array.
    7. Save.

2
Enable the lifecycle rules

Redeploy the site with the --enable-folder-expiry option. This operation will modify the S3 bucket to apply AWS Lifecycle Rules.

In the command line
bash
npx remotion lambda sites create --site-name=my-site-name --enable-folder-expiry
In the command line
bash
npx remotion lambda sites create --site-name=my-site-name --enable-folder-expiry
Verify that it worked

In your S3 bucket, under "Management", you should see 4 lifecycle rules.


Trigger a render with expiration

Valid values are "1-day", "3-days", "7-days" and "30-days".

bash
npx remotion lambda render testbed-v6 react-svg --delete-after="1-day"
bash
npx remotion lambda render testbed-v6 react-svg --delete-after="1-day"
Verify that it worked

All files should have an expiration rule and expiration date set when viewing the object properties.



AWS does not delete the file at the exact time, but the deletion will happen.

How it works

By applying the AWS Lifecycle rules, we are instructing AWS S3 to delete files based on their prefixes. When deleteAfter is defined with a value of "1-day", the renderId will be prefixed with 1-day, and the S3 key will start with renders/1-day-*, to which the deletion rule will be applied.
The basis of the deletion is based on the Last modified date of the file/folder.

deleteAfter valueRender Prefix
1-dayrenders/1-day
3-daysrenders/3-days
7-daysrenders/7-days
30-daysrenders/30-days

See also