Auto-delete renders
available from v4.0.32
To automatically delete renders and associated files after some time, you need to:
Enable the lifecycle rules on the AWS bucket.deleteAfter
option.
Apply the lifecycle rules
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:
- Upgrade to at least Remotion 4.0.32.
- Click here to go to the users section in the AWS console.
- Select your user.
- Under "Permissions policies", click your policy (underlined in blue)
- Choose the "JSON" mode for editing.
- Under the
"Sid": "Storage"
section, add"s3:PutLifecycleConfiguration"
to the"Action"
array. - Save.
Redeploy the site with the --enable-folder-expiry
option. This operation will modify the S3 bucket to apply AWS Lifecycle Rules.
- CLI
- Node.JS
In the command linebash
npx remotion lambda sites create --site-name=my-site-name --enable-folder-expiry
In the command linebash
npx remotion lambda sites create --site-name=my-site-name --enable-folder-expiry
deploy.mjsts
import {deploySite ,getOrCreateBucket } from "@remotion/lambda";importpath from "path";const {bucketName } = awaitgetOrCreateBucket ({region : "us-east-1",enableFolderExpiry : true,});const {serveUrl } = awaitdeploySite ({entryPoint :path .resolve (process .cwd (), "src/index.ts"),bucketName , // use the bucket with lifecyle rulesregion : "us-east-1",});console .log (serveUrl );
deploy.mjsts
import {deploySite ,getOrCreateBucket } from "@remotion/lambda";importpath from "path";const {bucketName } = awaitgetOrCreateBucket ({region : "us-east-1",enableFolderExpiry : true,});const {serveUrl } = awaitdeploySite ({entryPoint :path .resolve (process .cwd (), "src/index.ts"),bucketName , // use the bucket with lifecyle rulesregion : "us-east-1",});console .log (serveUrl );
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"
.
- CLI
- renderMediaOnLambda()
- renderStillOnLambda()
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"
render.tstsx
import {renderMediaOnLambda } from "@remotion/lambda/client";const {bucketName ,renderId } = awaitrenderMediaOnLambda ({region : "us-east-1",functionName : "remotion-render-bds9aab",composition : "MyVideo",serveUrl :"https://remotionlambda-qg35eyp1s1.s3.eu-central-1.amazonaws.com/sites/bf2jrbfkw",codec : "h264",deleteAfter : "1-day",});
render.tstsx
import {renderMediaOnLambda } from "@remotion/lambda/client";const {bucketName ,renderId } = awaitrenderMediaOnLambda ({region : "us-east-1",functionName : "remotion-render-bds9aab",composition : "MyVideo",serveUrl :"https://remotionlambda-qg35eyp1s1.s3.eu-central-1.amazonaws.com/sites/bf2jrbfkw",codec : "h264",deleteAfter : "1-day",});
render.tstsx
import {renderStillOnLambda } from "@remotion/lambda/client";const {bucketName ,renderId } = awaitrenderStillOnLambda ({region : "us-east-1",functionName : "remotion-render-bds9aab",composition : "MyVideo",serveUrl :"https://remotionlambda-qg35eyp1s1.s3.eu-central-1.amazonaws.com/sites/bf2jrbfkw",inputProps : {},privacy : "public",imageFormat : "png",deleteAfter : "1-day",});
render.tstsx
import {renderStillOnLambda } from "@remotion/lambda/client";const {bucketName ,renderId } = awaitrenderStillOnLambda ({region : "us-east-1",functionName : "remotion-render-bds9aab",composition : "MyVideo",serveUrl :"https://remotionlambda-qg35eyp1s1.s3.eu-central-1.amazonaws.com/sites/bf2jrbfkw",inputProps : {},privacy : "public",imageFormat : "png",deleteAfter : "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.
| Render Prefix |
---|---|
1-day | renders/1-day |
3-days | renders/3-days |
7-days | renders/7-days |
30-days | renders/30-days |