Setup
1. Install @remotion/lambda
Check the newest version number in the #lambda Discord channel
npm i @remotion/lambda@<version-number>
npm i @remotion/lambda@<version-number>
Also update all the other Remotion packages to have the same version: remotion, @remotion/cli, @remotion/bundler
tip
Make sure no package version number has a ^ character in front of it as it will install a different version.
Your package.json should look like the following:
json"@remotion/bundler": "3.0.0-lambda.[versionhash]","@remotion/cli": "3.0.0-lambda.[versionhash]","@remotion/lambda": "3.0.0-lambda.[versionhash]",// ..."remotion": "3.0.0-lambda.[versionhash]",
json"@remotion/bundler": "3.0.0-lambda.[versionhash]","@remotion/cli": "3.0.0-lambda.[versionhash]","@remotion/lambda": "3.0.0-lambda.[versionhash]",// ..."remotion": "3.0.0-lambda.[versionhash]",
tip
You can install @remotion/lambda in any project, not just a Remotion one, but remember to install react and react-dom peer dependencies
2. Create role policy
- Go to AWS account IAM Policies section
- Click on "Create policy"
- Click on JSON
- In your project, type
npx remotion lambda policies rolein the command line and copy it into the "JSON" field on AWS. - Click next. On the tags page, you don't need to fill in anything. Click next again.
- Give the policy exactly the name
remotion-lambda-policy. The other fields can be left as they are.
3. Create a role
- Go to AWS account IAM Roles section
- Under "Common use cases", select "Lambda". Click next.
- Under "Attach permissions policies", filter for
remotion-lambda-policyand click the checkbox to assign this policy. - Click next. No need to add tags. Click next again.
- Tags: Skip it
- In the final screen, name the role
remotion-lambda-roleexactly. You can leave the other fields as is. - Click "Create role" to confirm.
4. Create a user
- Go to AWS account IAM Users section
- Click
Add users - Enter any username, such as
remotion-user. - Check the "Access key - Programmatic access" option.
- Don't check the Management console access option. You don't need it.
- Click "Next: Permissions", then "Next: Tags", then "Next: Review" without changing any settings.
- Click "Create user", and ignore the warning that might appear.
- Reveal the Secret access key.
- Add a
.envfile to your project, and insert the following contents, using the credentials you just copied:
.envtxtREMOTION_AWS_ACCESS_KEY_ID=<Access key ID> REMOTION_AWS_SECRET_ACCESS_KEY=<Secret access key>
.envtxtREMOTION_AWS_ACCESS_KEY_ID=<Access key ID> REMOTION_AWS_SECRET_ACCESS_KEY=<Secret access key>
5. Add permissions to your user
- Go to AWS account IAM Users section
- Select the user you just created.
- Click "Add inline policy" on the right of the screen.
- Click the tab "JSON".
- Enter in your terminal:
npx remotion lambda policies userand copy into the AWS text field what gets printed. - Give the policy a name. For example
remotion-user-policy, but it can be anything.. - Click "Create policy" to confirm.
6. Optional: Validate the permission setup
- Run
npx remotion lambda policies validate
For the following steps, you may execute them on the CLI, or programmatically using the Node.JS APIs.
7. Deploy a function
- CLI
- Node.JS
Deploy a function by executing the following command:
bashnpx remotion lambda functions deploy
bashnpx remotion lambda functions deploy
You can deploy a function using deployFunction().
tsconst {functionName } = awaitdeployFunction ({region : "us-east-1",timeoutInSeconds : 120,memorySizeInMb : 1536,createCloudWatchLogGroup : true,architecture : "arm64",});
tsconst {functionName } = awaitdeployFunction ({region : "us-east-1",timeoutInSeconds : 120,memorySizeInMb : 1536,createCloudWatchLogGroup : true,architecture : "arm64",});
The function name is returned which you'll need for rendering.
8. Deploy a website
- CLI
- Node.JS
Run the following command to deploy your Remotion project to an S3 bucket. Pass as the last argument the entry file of the project - this is the file where registerRoot() is called.
bashnpx remotion lambda sites create src/index.tsx
bashnpx remotion lambda sites create src/index.tsx
A URL will be printed pointing to the deployed project.
First, you need to create an S3 bucket in your preferred region. If one already exists, it will be used instead:
tsimportpath from "path";import {deploySite ,getOrCreateBucket } from "@remotion/lambda";const {bucketName } = awaitgetOrCreateBucket ({region : "us-east-1",});
tsimportpath from "path";import {deploySite ,getOrCreateBucket } from "@remotion/lambda";const {bucketName } = awaitgetOrCreateBucket ({region : "us-east-1",});
Next, upload your Remotion project to an S3 bucket. Specify the entry point of your Remotion project, this is the file where registerRoot() is called.
tsconst {serveUrl } = awaitdeploySite ({bucketName ,entryPoint :path .resolve (process .cwd (), "src/index.tsx"),region : "us-east-1",});
tsconst {serveUrl } = awaitdeploySite ({bucketName ,entryPoint :path .resolve (process .cwd (), "src/index.tsx"),region : "us-east-1",});
You are now ready to render a video.
9. Render a video
- CLI
- Node.JS
Take the URL you received from the previous step and run the following command. Also pass in the ID of the composition you'd like to render.
bashnpx remotion lambda render <serve-url> <composition-id>
bashnpx remotion lambda render <serve-url> <composition-id>
Progress will be printed until the video finished rendering. Congrats! You rendered your first video using Remotion Lambda 🚀
You already have the function name from a previous step. But since you only need to deploy a function once, it's useful to retrieve the name of your deployed function programmatically before rendering a video in case your Node.JS program restarts. We can call getFunctions() with the compatibleOnly flag to get only functions with a matching version.
tsimport {getFunctions ,renderMediaOnLambda ,getRenderProgress ,} from "@remotion/lambda";constfunctions = awaitgetFunctions ({region : "us-east-1",compatibleOnly : true,});constfunctionName =functions [0].functionName ;
tsimport {getFunctions ,renderMediaOnLambda ,getRenderProgress ,} from "@remotion/lambda";constfunctions = awaitgetFunctions ({region : "us-east-1",compatibleOnly : true,});constfunctionName =functions [0].functionName ;
We can now trigger a render using the renderMediaOnLambda() function.
tsconst {renderId ,bucketName } = awaitrenderMediaOnLambda ({region : "us-east-1",functionName ,serveUrl :url ,composition : "HelloWorld",inputProps : {},codec : "h264-mkv",imageFormat : "jpeg",maxRetries : 1,framesPerLambda : 20,privacy : "public",});
tsconst {renderId ,bucketName } = awaitrenderMediaOnLambda ({region : "us-east-1",functionName ,serveUrl :url ,composition : "HelloWorld",inputProps : {},codec : "h264-mkv",imageFormat : "jpeg",maxRetries : 1,framesPerLambda : 20,privacy : "public",});
The render will now run and after a while the video will be available in your S3 bucket. You can at any time get the status of the video render by calling getRenderProgress().
tswhile (true) {await newPromise ((resolve ) =>setTimeout (resolve , 1000));constprogress = awaitgetRenderProgress ({renderId ,bucketName ,functionName ,region : "us-east-1",});if (progress .done ) {console .log ("Render finished!",progress .outputFile );process .exit (0);}if (progress .fatalErrorEncountered ) {console .error ("Error enountered",progress .errors );process .exit (1);}}
tswhile (true) {await newPromise ((resolve ) =>setTimeout (resolve , 1000));constprogress = awaitgetRenderProgress ({renderId ,bucketName ,functionName ,region : "us-east-1",});if (progress .done ) {console .log ("Render finished!",progress .outputFile );process .exit (0);}if (progress .fatalErrorEncountered ) {console .error ("Error enountered",progress .errors );process .exit (1);}}
This code will poll every second to check the progress of the video and exit the script if the render is done. Congrats! Check your S3 Bucket - you just rendered your first video using Remotion Lambda 🚀
Next steps
- Select which region(s) you want to run Remotion Lambda in.
- Familiarize yourself with the CLI and the Node.JS APIs (list in sidebar).
- Learn how to upgrade Remotion Lambda.
- Before going live, go through the Production checklist.
- If you have any questions, go through the FAQ or ask in our Discord channel