packages/docs/docs/lambda/autodelete.mdx
import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';
available from v4.0.32
To automatically delete renders and associated files after some time, you need to:
<Step>1</Step> Enable the lifecycle rules on the AWS bucket.
<Step>2</Step> Render a video with the <code>deleteAfter</code> option.
<Step>1</Step> <strong>Ensure the right permission</strong>
To put a lifecycle rule on the bucket, you need to have the s3:PutLifecycleConfiguration permission for your user.
"Sid": "Storage" section, add "s3:PutLifecycleConfiguration" to the "Action" array.<Step>2</Step> <strong>Enable the lifecycle rules</strong>
Redeploy the site with the --enable-folder-expiry option. This operation will modify the S3 bucket to apply AWS Lifecycle Rules.
<Tabs defaultValue="cli" values={[ { label: 'CLI', value: 'cli', }, { label: 'Node.JS', value: 'bucket', }, ] }> <TabItem value="cli">
npx remotion lambda sites create --site-name=my-site-name --enable-folder-expiry
import {deploySite, getOrCreateBucket} from '@remotion/lambda';
import path from 'path';
const {bucketName} = await getOrCreateBucket({
region: 'us-east-1',
enableFolderExpiry: true,
});
const {serveUrl} = await deploySite({
entryPoint: path.resolve(process.cwd(), 'src/index.ts'),
bucketName, // use the bucket with lifecyle rules
region: 'us-east-1',
});
console.log(serveUrl);
Valid values are "1-day", "3-days", "7-days" and "30-days".
<Tabs defaultValue="cli" values={[ { label: 'CLI', value: 'cli', }, { label: 'renderMediaOnLambda()', value: 'rendermedia', }, { label: 'renderStillOnLambda()', value: 'renderstill', }, ] }> <TabItem value="cli">
npx remotion lambda render testbed-v6 react-svg --delete-after="1-day"
// ---cut---
import {renderMediaOnLambda} from '@remotion/lambda/client';
const {bucketName, renderId} = await renderMediaOnLambda({
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',
});
// ---cut---
import {renderStillOnLambda} from '@remotion/lambda/client';
const {bucketName, renderId} = await renderStillOnLambda({
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',
});
AWS does not delete the file at the exact time, but the deletion will happen.
</details>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.