将生产环境和测试环境分开
无论你是从本地、测试还是生产环境调用,Lambda 函数内部的代码始终是相同的。
🌐 The code that is inside the Lambda function is always the same, no matter if you are calling it from a local, staging or production environment.
此外,每次使用 Remotion Lambda 执行的渲染在计算和存储方面都是完全独立的。
🌐 Also, each render executed with Remotion Lambda is completely isolated from another, in terms of compute and storage.
函数
🌐 Functions
每个 Lambda 函数都有一个配置,用于确定其唯一名称:
🌐 Each Lambda function has a configuration that determines its unique name:
- 超时
- 内存大小
- 磁盘大小
- Remotion 版本
如果你在不同环境中有相同的配置,你可以安全地重复使用相同的函数,因为每次执行都是隔离的——实际上,不支持复制函数,因为这样做没有任何效果。
🌐 If you have the same configuration in different environments, you can safely re-use the same function since each execution is isolated – in fact, duplicating the function is not supported because it achieves nothing.
如果你在一个环境中更改配置,请部署一个新函数,并保持旧函数的部署状态。 这允许你在不破坏其他环境的情况下安全地测试新函数。 对于已部署但未使用的函数,你不会产生任何费用。
🌐 If you are changing the configuration in one environment, deploy a new function and leave the old one deployed.
This allows you to safely test new functions without breaking the other environments.
You don't incur any costs for functions that are deployed but not used.
网站
🌐 Sites
我们建议在创建网站时使用 --site-name 将网站范围限定在特定环境。例如,使用 --site-name=remotion-production 和 --site-name=remotion-staging。
🌐 We recommend to scope the site to a specific environment using --site-name when creating a site. For example, use --site-name=remotion-production and --site-name=remotion-staging.
一个网站包含你的 React / Remotion 代码,并且可能会频繁更改。
确保每次更改代码或升级 Remotion 后都更新你的网站,并且如果其他环境不同,不要在这些环境中使用该网站。
🌐 A site contains your React / Remotion code and might change frequently.
Make sure to update your site whenever you make changes to your code or upgrade Remotion, and to not use the site for other environments if they differ.
水桶
🌐 Buckets
每个区域只能为 Remotion Lambda 使用一个存储桶,但其中的资源可以进行范围划分。
🌐 Just one bucket per region can be used for Remotion Lambda, but the resources in it can be scoped.
一个桶包含两个文件夹:
🌐 A bucket contains 2 folders:
sites/文件夹用于你的网站renders/文件夹用于你的渲染
在创建网站时,你应该选择 范围你的站点 选项。
在渲染时,渲染会自动被范围化,通过在 renders/ 文件夹内创建带有唯一 ID 的子文件夹来实现。
🌐 You should scope your sites option when creating a site.
The renders are automatically scoped when rendering by creating subfolders with unique IDs within the renders/ folder.
在所有环境中使用同一个存储桶是安全的。
使用privacy选项来使渲染内容私有。
这些网站必须是公开的,因为它们是通过 HTTP 访问的。
🌐 It is safe to use the same bucket for all environments.
Use the privacy option to make renders private.
The sites must be public because they are accessed via HTTP.
常见问题
🌐 Common questions
我为什么不能重命名这个函数?
🌐 Why can't I rename the function?
[npx remotion lambda render](/docs/lambda/cli/render)命令用于查找符合此约定的函数。- 在默认的用户策略下,Remotion Lambda 会限制自己访问不符合此约定的函数。
- 你可以使用
speculateFunctionName()函数来节省一次 API 调用。 - 如果你只有一个具有相同配置的函数,该函数在之前调用后更有可能保持热状态。
- 重命名这个函数没有任何好处。
如果我想为两个不同的项目设置两个功能怎么办?
🌐 What if I want to have two functions for two different projects?
一个函数并不依附于某个项目。
🌐 A function is not tied to a project.
每个函数都是包含相同代码的二进制文件。每个 Remotion Lambda 用户在他们的函数中运行完全相同的代码。
🌐 Each function is a binary that contains the same code.
Every Remotion Lambda user runs the exact same code in their function.
你编写的 React 代码不包含在函数中,它托管在服务器 URL 上。
🌐 The React code you write is not contained in the function, it is hosted on the Serve URL.
每个函数调用都是独立的,它们之间不会互相冲突。有一个并发限制,但这是按区域计算的,而不是按函数计算的。
🌐 Each function invocation is isolated and they cannot conflict each other. There is a concurrency limit, but it is per region, not per function.
我需要分开生产、预发布和开发环境
🌐 I need to separate production, staging and development
函数调用彼此之间不会冲突。函数也不包含你编写的任何代码,它们是二进制的,每个 Remotion Lambda 用户运行的代码完全相同。
🌐 Function invocations don't conflict each other.
Functions also don't contain any code that you write, they are binary and every Remotion Lambda user runs the exact same code.
不可能因为一个糟糕的预发布部署而影响生产功能。 因此,我们建议在所有环境中使用相同的功能。
🌐 It is impossible for a bad staging deployment to affect the production function.
Therefore, we recommend to use the same function for all environments.
我想为不同的功能设置不同的配置
🌐 I want to have different configurations for different functions
这是支持的!你可以有多个具有不同配置的函数。 只是无法拥有多个共享完全相同配置的函数:
🌐 This is supported! You can have multiple functions with different configurations.
It is only not possible to have multiple functions that share the exact same configuration:
- 超时
- 随机存取存储器
- 地区
- 磁盘大小
- Remotion 版本
要区分应使用哪个函数,请将函数名称明确传递给 renderMediaOnLambda()。
你可以将 --function-name 传递给 npx remotion lambda render
🌐 To distinguish which function should be used, pass the function name explicitly to renderMediaOnLambda().
You can pass --function-name to npx remotion lambda render
我想部署多个项目
🌐 I want to deploy multiple projects
可以在不同的 服务 URL 下部署多个站点。
此约定仅适用于函数,这些函数不包含你编写的任何代码。
🌐 It is possible deploy multiple sites under different Serve URLs.
This convention only applies to functions, which do not contain any code that you write.
我想部署多个函数以在它们之间进行负载均衡
🌐 I want to deploy multiple functions to load-balance between them
你不需要这样做,因为你可以同时多次调用一个函数。 每个函数没有并发限制,但每个区域和账户有并发限制。 因此,在同一个区域和账户中拥有多个相同的函数来进行负载均衡是没有益处的。
🌐 You do not need to do this, because you can invoke a function multiple times concurrently.
There is no concurrency limit per function, but a concurrency limit per region and account.
Therefore there is no benefit in having multiple identical functions in the same region and account for load-balancing.
另请参阅
🌐 See also