Skip to main content

设置

Also available as a 18min video
如何设置 Remotion Lambda

1. 安装 @remotion/lambda

🌐 1. Install @remotion/lambda

npx remotion add @remotion/lambda

2. 创建角色策略

🌐 2. Create role policy

  • 前往 AWS 账户 IAM 策略部分
  • 点击“创建策略”
  • 点击 JSON
  • 在你的项目中,在命令行中输入 npx remotion lambda policies role 并将其复制到 AWS 的“JSON”字段中。
  • 点击下一步。将策略完全命名为remotion-lambda-policy。其他字段可以保持不变。
  • 在标签页面上,你不需要填写任何内容。再次点击下一步。

3. 创建一个角色

🌐 3. Create a role

  • 前往 AWS 账户 IAM 角色部分
  • 点击“创建角色”。
  • 在“用例”下,选择“Lambda”。点击下一步。
  • 在“权限策略”下,筛选 remotion-lambda-policy 并勾选复选框以分配此策略。点击下一步。
  • 在最后一步,准确地命名角色 remotion-lambda-role。其他字段可以保持原样。
  • 点击“创建角色”以确认。

4. 创建用户

🌐 4. Create a user

  • 前往 AWS 账户 IAM 用户部分
  • 点击 Add users
  • 输入任意用户名,例如 remotion-user
  • 不要勾选“启用控制台访问”选项。你不需要它。
  • 点击“下一步”。
  • 再次点击“下一步”,无需更改任何设置。你现在应该在“查看并创建”步骤。
  • 点击“创建用户”。

5. 为用户创建访问密钥

🌐 5. Create an access key for the user

  • 前往 AWS 账户 IAM 用户部分
  • 点击在第4步中创建的用户的名称。
  • 导航到“安全凭证”选项卡,然后向下滚动到“访问密钥”部分。
  • 点击“创建访问密钥”按钮。
  • 选择“在 AWS 计算服务上运行的应用”
  • 忽略可能出现的警告,并勾选“我理解这些建议……”复选框。
  • 点击“下一步”。
  • 点击“创建访问密钥”。
  • 在项目根目录添加一个 .env 文件,并以以下格式添加你刚刚复制的凭证:
.env
REMOTION_AWS_ACCESS_KEY_ID=<Access key ID> REMOTION_AWS_SECRET_ACCESS_KEY=<Secret access key>

6. 为你的用户添加权限

🌐 6. Add permissions to your user

  • 前往 AWS 账户 IAM 用户部分
  • 选择你刚创建的用户。
  • 在“权限策略”面板中的“添加权限”下拉菜单下点击“添加内联策略”。
  • 点击“JSON”标签。
  • 在终端中输入:npx remotion lambda policies user 并将打印出的内容复制到 AWS 文本字段中。
  • 点击“查看政策”。
  • 给政策起一个名字。例如 remotion-user-policy,但可以是任何名称。
  • 点击“创建策略”以确认。

7. 可选:验证权限设置

🌐 7. Optional: Validate the permission setup

检查所有用户权限,并通过执行以下命令将其与 AWS 策略模拟器进行验证:

🌐 Check all user permissions and validate them against the AWS Policy simulator by executing the following command:

npx remotion lambda policies validate

对于以下步骤,你可以在命令行接口上执行它们,或者使用 Node.JS API 以编程方式执行。

🌐 For the following steps, you may execute them on the CLI, or programmatically using the Node.JS APIs.

8. 部署一个函数

🌐 8. Deploy a function

通过执行以下命令,在你的 AWS 账户中部署一个可以渲染视频的函数:

🌐 Deploy a function that can render videos into your AWS account by executing the following command:

npx remotion lambda functions deploy

该函数由必要的二进制文件和 JavaScript 代码组成,可以获取一个 服务 URL 并从中进行渲染。函数与 Remotion 版本绑定,如果你升级 Remotion,你 需要部署一个新函数。函数不包括你的 Remotion 代码,这部分将在下一步中部署。

🌐 The function consists of necessary binaries and JavaScript code that can take a serve URL and make renders from it. A function is bound to the Remotion version, if you upgrade Remotion, you need to deploy a new function. A function does not include your Remotion code, it will be deployed in the next step instead.

9. 部署一个网站

🌐 9. Deploy a site

运行以下命令将你的 Remotion 项目部署到 S3 存储桶。将项目的 入口点 作为最后一个参数传递。

🌐 Run the following command to deploy your Remotion project to an S3 bucket. Pass as the last argument the entry point of the project.

npx remotion lambda sites create src/index.ts --site-name=my-video

将打印一个指向已部署项目的 Serve URL

🌐 A Serve URL will be printed pointing to the deployed project.

当你将来更新你的 Remotion 代码时,请重新部署你的网站。传递相同的 --site-name 以覆盖之前的部署。如果你不传递 --site-name,每次部署都会生成一个唯一的 URL。

🌐 When you update your Remotion code in the future, redeploy your site. Pass the same --site-name to overwrite the previous deploy. If you don't pass --site-name, a unique URL will be generated on every deploy.

10. 检查 AWS 并发限制

🌐 10. Check AWS concurrency limit

检查 AWS 分配给你账户的并发限制:

🌐 Check the concurrency limit that AWS has given to your account:

npx remotion lambda quotas

默认情况下,每个区域有 1000 个并发调用。但是,新账户可能有一个 低至 10 的限制。每次 Remotion 渲染可能会同时使用多达 200 个函数,因此如果你的分配限制非常低, 你可能想立即申请增加

🌐 By default, it is 1000 concurrent invocations per region. However, new accounts might have a limit as low as 10. Each Remotion render may use as much as 200 functions per render concurrently, so if your assigned limit is very low, you might want to request an increase right away.

11. 渲染视频

🌐 11. Render a video

使用你在第9步收到的URL——你的“服务URL”——并运行以下命令。同时传入你想要渲染的作品ID

🌐 Take the URL you received from the step 9 - your "serve URL" - and run the following command. Also pass in the ID of the composition you'd like to render.

npx remotion lambda render <serve-url> <composition-id>

进度将在视频渲染完成前打印。恭喜!你已经使用 Remotion Lambda 渲染了你的第一个视频 🚀

🌐 Progress will be printed until the video finished rendering. Congrats! You rendered your first video using Remotion Lambda 🚀

下一步

🌐 Next steps