Skip to content

🎥 Make videos programmatically with React

allow to customize lambda layers

Jonny Burger3903d70f0d6b
diff --git a/packages/docs/docs/lambda/custom-layers.md b/packages/docs/docs/lambda/custom-layers.md
new file mode 100644
index 0000000000..df70faef2e
--- /dev/null
+++ b/packages/docs/docs/lambda/custom-layers.md
@@ -0,0 +1,154 @@
+---
+title: Custom Layers
+slug: custom-layers
+---
+
+import Tabs from '@theme/Tabs';
+import TabItem from '@theme/TabItem';
+
+The Lambda function [includes FFMPEG, Chrome and base fonts by default](/docs/lambda/runtime).
+
+In some advanced use cases, you want to replace certain parts of the stack:
+
+- Use another Chrome version (binaries can be obtained from [chromiumforlambda.com](https://www.chromiumforlambda.com))
+- Replace default fonts or emojis (such as Apple Emoji font)
+
+Before you create a custom stack, feel free to contact us to see if Remotion can provide the changes upstream.
+
+## Ensure Remotion version
+
+Customizing Remotion Lambda Layers is possible from v3.0.17.
+Lambda binaries might change in minor Remotion versions, it is your responsibility to keep your versions up to date.
+
+## Creating a custom binary
+
+Go to the [`remotion-dev/lambda-layers`](https://github.com/remotion-dev/lambda-binaries) repository and clone it.
+
+The folders `chromium`, `ffmpeg` and `fonts` contain the binaries for the ARM version.
+The folders `chromium-x64`, `ffmpeg-x64` and `fonts-x64` contain the binaries for the x86_64 version of Lambda.
+The default and recommended version is the ARM one.
+
+Put the files that you want in the corresponding folders - for example, add the Apple Emoji Font `AppleColorEmoji.ttf` into the `fonts/.fonts/NotoSans/` folder.
+
+Since the AWS Lambda layers may not exceed 250MB extracted, we need to sacrifice an equal amount of other files - for example by removing `fonts/.fonts/NotoColorEmoji.ttf` and `fonts/.fonts/NotoSansCJKjp-Regular.otf`.
+
+You can see the size of the folders by running:
+
+```bash
+sh size.sh
+```
+
+If you are done with your changes, run:
+
+```bash
+sh make.sh
+```
+
+This will zip the layers and put them as artifacts in the `out` directory.
+
+## Creating a Lambda layer
+
+- Go to your AWS console, select the Lambda product, then select "Layers":
+
+<img src="/img/lambda-layers-console.png" />
+
+- Select "Create layer" and fill out the name. Upload the created layer from the `out` folder into the form. The fields "Compatible architectures", "Compatible runtimes" and "License" are optional.
+
+- Once the layer is created, you will get a version ARN (example: `arn:aws:lambda:us-east-1:123456789012:layer:apple-emoji:1`). Copy it.
+
+:::note
+You need to do this for every AWS region you want to use Remotion Lambda in.
+:::
+
+## Update the Lambda function
+
+Before you continue, make sure a Remotion Lambda function is deployed.
+
+To switch out the layer of a deployed Lambda function, you can either do it via the AWS console or use a Node.JS script that you can run after every function deploy.
+
+<Tabs
+defaultValue="node"
+values={[
+{ label: 'Node.JS', value: 'node', },
+{ label: 'AWS console', value: 'deploy', },
+]
+}>
+<TabItem value="deploy">
+
+- Go to your AWS console, select the Lambda product, then select the Lambda function you would like to update.
+- Click on "Layers":
+
+<img src="/img/lambda-single-layer.png" />
+
+- Click on "Edit", then select the layer you'd like to replace, then click "Remove", then click "Save".
+- Once returned, click "Add a layer", then click "Specify an ARN", then paste in the layer version ARN you retrieved from the previous step.
+- Click "Verify" and then "Add".
+
+Congrats! You customized your Lambda function.
+
+</TabItem>
+<TabItem value="node">
+
+Before you can update a function via the Node.JS APIs, you need to [add another rule to your user role](/docs/lambda/setup#5-add-permissions-to-your-user):
+
+```json
+[
+ {
+ "Sid": "UpdateFunction",
+ "Effect": "Allow",
+ "Action": [
+ "lambda:GetFunctionConfiguration",
+ "lambda:UpdateFunctionConfiguration"
+ ],
+ "Resource": ["arn:aws:lambda:*:*:function:remotion-render-*"]
+ },
+ {
+ "Sid": "GetOwnLayerVersion",
+ "Effect": "Allow",
+ "Action": ["lambda:GetLayerVersion"],
+ "Resource": ["*"]
+ }
+]
+```
+
+Given a region, function name, layer to remove and layer to add, you can use the following snippet to update a function with custom layers
+
+```ts
+import { AwsRegion, getAwsClient } from "@remotion/lambda";
+
+// Customize these parameters
+const REGION: AwsRegion = "us-east-1";
+const FUNCTION_NAME = "remotion-render-2022-06-02-mem3000mb-disk512mb-120sec";
+const LAYER_TO_REMOVE = /fonts/;
+const LAYER_TO_ADD = "arn:aws:lambda:us-east-1:1234567891:layer:apple-emoji:1";
+
+const { client, sdk } = getAwsClient({
+ region: REGION,
+ service: "lambda",
+});
+
+const fnConfig = await client.send(
+ new sdk.GetFunctionConfigurationCommand({
+ FunctionName: FUNCTION_NAME,
+ })
+);
+
+if (!fnConfig) {
+ throw new Error(`Function ${FUNCTION_NAME} not deployed`);
+}
+
+await client.send(
+ new sdk.UpdateFunctionConfigurationCommand({
+ FunctionName: FUNCTION_NAME,
+ Layers: [
+ ...(fnConfig.Layers ?? [])
+ .filter((l) => !l.Arn?.match(LAYER_TO_REMOVE))
+ .map((l) => l.Arn as string),
+ LAYER_TO_ADD,
+ ],
+ })
+);
+```
+
+</TabItem>
+</Tabs>
diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.js
index 9793c03acd..346488408c 100644
--- a/packages/docs/sidebars.js
+++ b/packages/docs/sidebars.js
@@ -29,6 +29,7 @@ module.exports = {
"lambda/disk-size",
"lambda/faq",
"lambda/light-client",
+ "lambda/custom-layers",
{
collapsed: false,
type: "category",
diff --git a/packages/docs/static/img/lambda-layers-console.png b/packages/docs/static/img/lambda-layers-console.png
new file mode 100644
index 0000000000..fc1f5fdafe
Binary files /dev/null and b/packages/docs/static/img/lambda-layers-console.png differ
diff --git a/packages/docs/static/img/lambda-single-layer.png b/packages/docs/static/img/lambda-single-layer.png
new file mode 100644
index 0000000000..a78c90200c
Binary files /dev/null and b/packages/docs/static/img/lambda-single-layer.png differ
diff --git a/packages/lambda/src/admin/make-layer-public.ts b/packages/lambda/src/admin/make-layer-public.ts
index 18c37e39eb..d0baf195a5 100644
--- a/packages/lambda/src/admin/make-layer-public.ts
+++ b/packages/lambda/src/admin/make-layer-public.ts
@@ -42,7 +42,7 @@ const layerInfo: HostedLayers = {
};
const makeLayerPublic = async () => {
- const layers = ['remotion', 'ffmpeg', 'chromium'] as const;
+ const layers = ['fonts', 'ffmpeg', 'chromium'] as const;
for (const architecture of archictures) {
for (const region of getRegions()) {
for (const layer of layers) {
@@ -51,7 +51,7 @@ const makeLayerPublic = async () => {
new PublishLayerVersionCommand({
Content: {
S3Bucket: 'remotionlambda-binaries-' + region,
- S3Key: `remotion-layer-${layer}-v5-${architecture}.zip`,
+ S3Key: `remotion-layer-${layer}-v6-${architecture}.zip`,
},
LayerName: layerName,
LicenseInfo:
@@ -59,7 +59,7 @@ const makeLayerPublic = async () => {
? 'Chromium 101, compiled from source. Read Chromium License: https://chromium.googlesource.com/chromium/src/+/refs/heads/main/LICENSE'
: layer === 'ffmpeg'
? 'Compiled from FFMPEG source. Read FFMPEG license: https://ffmpeg.org/legal.html'
- : 'Contains Amazon Linux .so files and Noto Sans font. Read Noto Sans License: https://fonts.google.com/noto/specimen/Noto+Sans/about',
+ : 'Contains Noto Sans font. Read Noto Sans License: https://fonts.google.com/noto/specimen/Noto+Sans/about',
CompatibleRuntimes: runtimes,
Description: CURRENT_VERSION,
})
diff --git a/packages/lambda/src/api/iam-validation/user-permissions.ts b/packages/lambda/src/api/iam-validation/user-permissions.ts
index ef65b21871..ede68a3c60 100644
--- a/packages/lambda/src/api/iam-validation/user-permissions.ts
+++ b/packages/lambda/src/api/iam-validation/user-permissions.ts
@@ -70,6 +70,7 @@ export const requiredPermissions: {
lambda.InvokeAsync,
lambda.InvokeFunction,
lambda.CreateFunction,
+ lambda.UpdateFunctionConfiguration,
lambda.DeleteFunction,
lambda.PutFunctionEventInvokeConfig,
],
@@ -87,4 +88,8 @@ export const requiredPermissions: {
actions: [lambda.GetLayerVersion],
resource: [REMOTION_HOSTED_LAYER_ARN],
},
+ {
+ id: 'Update binaries',
+ actions: ['lambda:UpdateFunctionConfiguration'],
+ },
];
diff --git a/packages/lambda/src/shared/hosted-layers.ts b/packages/lambda/src/shared/hosted-layers.ts
index 20dc78ed2b..f0da32e876 100644
--- a/packages/lambda/src/shared/hosted-layers.ts
+++ b/packages/lambda/src/shared/hosted-layers.ts
@@ -14,171 +14,171 @@ export const hostedLayers: HostedLayers = {
'ap-northeast-1': [
{
layerArn:
- 'arn:aws:lambda:ap-northeast-1:678892195805:layer:remotion-binaries-remotion-arm64',
- version: 4,
+ 'arn:aws:lambda:ap-northeast-1:678892195805:layer:remotion-binaries-fonts-arm64',
+ version: 1,
},
{
layerArn:
'arn:aws:lambda:ap-northeast-1:678892195805:layer:remotion-binaries-ffmpeg-arm64',
- version: 4,
+ version: 5,
},
{
layerArn:
'arn:aws:lambda:ap-northeast-1:678892195805:layer:remotion-binaries-chromium-arm64',
- version: 4,
+ version: 5,
},
],
'ap-south-1': [
{
layerArn:
- 'arn:aws:lambda:ap-south-1:678892195805:layer:remotion-binaries-remotion-arm64',
- version: 4,
+ 'arn:aws:lambda:ap-south-1:678892195805:layer:remotion-binaries-fonts-arm64',
+ version: 1,
},
{
layerArn:
'arn:aws:lambda:ap-south-1:678892195805:layer:remotion-binaries-ffmpeg-arm64',
- version: 4,
+ version: 5,
},
{
layerArn:
'arn:aws:lambda:ap-south-1:678892195805:layer:remotion-binaries-chromium-arm64',
- version: 4,
+ version: 5,
},
],
'ap-southeast-1': [
{
layerArn:
- 'arn:aws:lambda:ap-southeast-1:678892195805:layer:remotion-binaries-remotion-arm64',
- version: 4,
+ 'arn:aws:lambda:ap-southeast-1:678892195805:layer:remotion-binaries-fonts-arm64',
+ version: 1,
},
{
layerArn:
'arn:aws:lambda:ap-southeast-1:678892195805:layer:remotion-binaries-ffmpeg-arm64',
- version: 4,
+ version: 5,
},
{
layerArn:
'arn:aws:lambda:ap-southeast-1:678892195805:layer:remotion-binaries-chromium-arm64',
- version: 4,
+ version: 5,
},
],
'ap-southeast-2': [
{
layerArn:
- 'arn:aws:lambda:ap-southeast-2:678892195805:layer:remotion-binaries-remotion-arm64',
- version: 4,
+ 'arn:aws:lambda:ap-southeast-2:678892195805:layer:remotion-binaries-fonts-arm64',
+ version: 1,
},
{
layerArn:
'arn:aws:lambda:ap-southeast-2:678892195805:layer:remotion-binaries-ffmpeg-arm64',
- version: 4,
+ version: 5,
},
{
layerArn:
'arn:aws:lambda:ap-southeast-2:678892195805:layer:remotion-binaries-chromium-arm64',
- version: 4,
+ version: 5,
},
],
'eu-central-1': [
{
layerArn:
- 'arn:aws:lambda:eu-central-1:678892195805:layer:remotion-binaries-remotion-arm64',
- version: 4,
+ 'arn:aws:lambda:eu-central-1:678892195805:layer:remotion-binaries-fonts-arm64',
+ version: 1,
},
{
layerArn:
'arn:aws:lambda:eu-central-1:678892195805:layer:remotion-binaries-ffmpeg-arm64',
- version: 4,
+ version: 5,
},
{
layerArn:
'arn:aws:lambda:eu-central-1:678892195805:layer:remotion-binaries-chromium-arm64',
- version: 4,
+ version: 5,
},
],
'eu-west-1': [
{
layerArn:
- 'arn:aws:lambda:eu-west-1:678892195805:layer:remotion-binaries-remotion-arm64',
- version: 4,
+ 'arn:aws:lambda:eu-west-1:678892195805:layer:remotion-binaries-fonts-arm64',
+ version: 1,
},
{
layerArn:
'arn:aws:lambda:eu-west-1:678892195805:layer:remotion-binaries-ffmpeg-arm64',
- version: 4,
+ version: 5,
},
{
layerArn:
'arn:aws:lambda:eu-west-1:678892195805:layer:remotion-binaries-chromium-arm64',
- version: 4,
+ version: 5,
},
],
'eu-west-2': [
{
layerArn:
- 'arn:aws:lambda:eu-west-2:678892195805:layer:remotion-binaries-remotion-arm64',
- version: 4,
+ 'arn:aws:lambda:eu-west-2:678892195805:layer:remotion-binaries-fonts-arm64',
+ version: 1,
},
{
layerArn:
'arn:aws:lambda:eu-west-2:678892195805:layer:remotion-binaries-ffmpeg-arm64',
- version: 4,
+ version: 5,
},
{
layerArn:
'arn:aws:lambda:eu-west-2:678892195805:layer:remotion-binaries-chromium-arm64',
- version: 4,
+ version: 5,
},
],
'us-east-1': [
{
layerArn:
- 'arn:aws:lambda:us-east-1:678892195805:layer:remotion-binaries-remotion-arm64',
- version: 8,
+ 'arn:aws:lambda:us-east-1:678892195805:layer:remotion-binaries-fonts-arm64',
+ version: 1,
},
{
layerArn:
'arn:aws:lambda:us-east-1:678892195805:layer:remotion-binaries-ffmpeg-arm64',
- version: 8,
+ version: 9,
},
{
layerArn:
'arn:aws:lambda:us-east-1:678892195805:layer:remotion-binaries-chromium-arm64',
- version: 8,
+ version: 9,
},
],
'us-east-2': [
{
layerArn:
- 'arn:aws:lambda:us-east-2:678892195805:layer:remotion-binaries-remotion-arm64',
- version: 4,
+ 'arn:aws:lambda:us-east-2:678892195805:layer:remotion-binaries-fonts-arm64',
+ version: 1,
},
{
layerArn:
'arn:aws:lambda:us-east-2:678892195805:layer:remotion-binaries-ffmpeg-arm64',
- version: 4,
+ version: 5,
},
{
layerArn:
'arn:aws:lambda:us-east-2:678892195805:layer:remotion-binaries-chromium-arm64',
- version: 4,
+ version: 5,
},
],
'us-west-2': [
{
layerArn:
- 'arn:aws:lambda:us-west-2:678892195805:layer:remotion-binaries-remotion-arm64',
- version: 4,
+ 'arn:aws:lambda:us-west-2:678892195805:layer:remotion-binaries-fonts-arm64',
+ version: 1,
},
{
layerArn:
'arn:aws:lambda:us-west-2:678892195805:layer:remotion-binaries-ffmpeg-arm64',
- version: 4,
+ version: 5,
},
{
layerArn:
'arn:aws:lambda:us-west-2:678892195805:layer:remotion-binaries-chromium-arm64',
- version: 4,
+ version: 5,
},
],
},
@@ -186,171 +186,171 @@ export const hostedLayers: HostedLayers = {
'ap-northeast-1': [
{
layerArn:
- 'arn:aws:lambda:ap-northeast-1:678892195805:layer:remotion-binaries-remotion-x86_64',
- version: 4,
+ 'arn:aws:lambda:ap-northeast-1:678892195805:layer:remotion-binaries-fonts-x86_64',
+ version: 1,
},
{
layerArn:
'arn:aws:lambda:ap-northeast-1:678892195805:layer:remotion-binaries-ffmpeg-x86_64',
- version: 4,
+ version: 5,
},
{
layerArn:
'arn:aws:lambda:ap-northeast-1:678892195805:layer:remotion-binaries-chromium-x86_64',
- version: 4,
+ version: 5,
},
],
'ap-south-1': [
{
layerArn:
- 'arn:aws:lambda:ap-south-1:678892195805:layer:remotion-binaries-remotion-x86_64',
- version: 4,
+ 'arn:aws:lambda:ap-south-1:678892195805:layer:remotion-binaries-fonts-x86_64',
+ version: 1,
},
{
layerArn:
'arn:aws:lambda:ap-south-1:678892195805:layer:remotion-binaries-ffmpeg-x86_64',
- version: 4,
+ version: 5,
},
{
layerArn:
'arn:aws:lambda:ap-south-1:678892195805:layer:remotion-binaries-chromium-x86_64',
- version: 4,
+ version: 5,
},
],
'ap-southeast-1': [
{
layerArn:
- 'arn:aws:lambda:ap-southeast-1:678892195805:layer:remotion-binaries-remotion-x86_64',
- version: 4,
+ 'arn:aws:lambda:ap-southeast-1:678892195805:layer:remotion-binaries-fonts-x86_64',
+ version: 1,
},
{
layerArn:
'arn:aws:lambda:ap-southeast-1:678892195805:layer:remotion-binaries-ffmpeg-x86_64',
- version: 4,
+ version: 5,
},
{
layerArn:
'arn:aws:lambda:ap-southeast-1:678892195805:layer:remotion-binaries-chromium-x86_64',
- version: 4,
+ version: 5,
},
],
'ap-southeast-2': [
{
layerArn:
- 'arn:aws:lambda:ap-southeast-2:678892195805:layer:remotion-binaries-remotion-x86_64',
- version: 4,
+ 'arn:aws:lambda:ap-southeast-2:678892195805:layer:remotion-binaries-fonts-x86_64',
+ version: 1,
},
{
layerArn:
'arn:aws:lambda:ap-southeast-2:678892195805:layer:remotion-binaries-ffmpeg-x86_64',
- version: 4,
+ version: 5,
},
{
layerArn:
'arn:aws:lambda:ap-southeast-2:678892195805:layer:remotion-binaries-chromium-x86_64',
- version: 4,
+ version: 5,
},
],
'eu-central-1': [
{
layerArn:
- 'arn:aws:lambda:eu-central-1:678892195805:layer:remotion-binaries-remotion-x86_64',
- version: 4,
+ 'arn:aws:lambda:eu-central-1:678892195805:layer:remotion-binaries-fonts-x86_64',
+ version: 1,
},
{
layerArn:
'arn:aws:lambda:eu-central-1:678892195805:layer:remotion-binaries-ffmpeg-x86_64',
- version: 4,
+ version: 5,
},
{
layerArn:
'arn:aws:lambda:eu-central-1:678892195805:layer:remotion-binaries-chromium-x86_64',
- version: 4,
+ version: 5,
},
],
'eu-west-1': [
{
layerArn:
- 'arn:aws:lambda:eu-west-1:678892195805:layer:remotion-binaries-remotion-x86_64',
- version: 4,
+ 'arn:aws:lambda:eu-west-1:678892195805:layer:remotion-binaries-fonts-x86_64',
+ version: 1,
},
{
layerArn:
'arn:aws:lambda:eu-west-1:678892195805:layer:remotion-binaries-ffmpeg-x86_64',
- version: 4,
+ version: 5,
},
{
layerArn:
'arn:aws:lambda:eu-west-1:678892195805:layer:remotion-binaries-chromium-x86_64',
- version: 4,
+ version: 5,
},
],
'eu-west-2': [
{
layerArn:
- 'arn:aws:lambda:eu-west-2:678892195805:layer:remotion-binaries-remotion-x86_64',
- version: 4,
+ 'arn:aws:lambda:eu-west-2:678892195805:layer:remotion-binaries-fonts-x86_64',
+ version: 1,
},
{
layerArn:
'arn:aws:lambda:eu-west-2:678892195805:layer:remotion-binaries-ffmpeg-x86_64',
- version: 4,
+ version: 5,
},
{
layerArn:
'arn:aws:lambda:eu-west-2:678892195805:layer:remotion-binaries-chromium-x86_64',
- version: 4,
+ version: 5,
},
],
'us-east-1': [
{
layerArn:
- 'arn:aws:lambda:us-east-1:678892195805:layer:remotion-binaries-remotion-x86_64',
- version: 8,
+ 'arn:aws:lambda:us-east-1:678892195805:layer:remotion-binaries-fonts-x86_64',
+ version: 1,
},
{
layerArn:
'arn:aws:lambda:us-east-1:678892195805:layer:remotion-binaries-ffmpeg-x86_64',
- version: 8,
+ version: 9,
},
{
layerArn:
'arn:aws:lambda:us-east-1:678892195805:layer:remotion-binaries-chromium-x86_64',
- version: 8,
+ version: 9,
},
],
'us-east-2': [
{
layerArn:
- 'arn:aws:lambda:us-east-2:678892195805:layer:remotion-binaries-remotion-x86_64',
- version: 4,
+ 'arn:aws:lambda:us-east-2:678892195805:layer:remotion-binaries-fonts-x86_64',
+ version: 1,
},
{
layerArn:
'arn:aws:lambda:us-east-2:678892195805:layer:remotion-binaries-ffmpeg-x86_64',
- version: 4,
+ version: 5,
},
{
layerArn:
'arn:aws:lambda:us-east-2:678892195805:layer:remotion-binaries-chromium-x86_64',
- version: 4,
+ version: 5,
},
],
'us-west-2': [
{
layerArn:
- 'arn:aws:lambda:us-west-2:678892195805:layer:remotion-binaries-remotion-x86_64',
- version: 4,
+ 'arn:aws:lambda:us-west-2:678892195805:layer:remotion-binaries-fonts-x86_64',
+ version: 1,
},
{
layerArn:
'arn:aws:lambda:us-west-2:678892195805:layer:remotion-binaries-ffmpeg-x86_64',
- version: 4,
+ version: 5,
},
{
layerArn:
'arn:aws:lambda:us-west-2:678892195805:layer:remotion-binaries-chromium-x86_64',
- version: 4,
+ version: 5,
},
],
},