🎥 Make videos programmatically with React
remove lambda layers
Jonny Burgeraf3055173621
diff --git a/packages/docs/docs/deployfunction.md b/packages/docs/docs/deployfunction.mdindex 46a81f8a21..58835d78bd 100644--- a/packages/docs/docs/deployfunction.md+++ b/packages/docs/docs/deployfunction.md@@ -6,19 +6,15 @@ slug: /lambda/deployfunctionCreates an [AWS Lambda](https://aws.amazon.com/lambda/) function in your AWS account that will be able to render a video in the cloud.-Before calling `deployFunction()`, you need to deploy the necessary binaries and obtain the identifier for the Lambda Layer. You can do so by calling [`ensureLambdaBinaries()`](/docs/lambda/ensurelambdabinaries).-## Example```ts twoslash// @module: esnext// @target: es2017-import {deployFunction, ensureLambdaBinaries} from '@remotion/lambda';+import {deployFunction} from '@remotion/lambda';-const {layerArn} = await ensureLambdaBinaries('us-east-1');const {functionName} = await deployFunction({- layerArn,region: 'us-east-1',timeoutInSeconds: 120,memorySizeInMb: 1024@@ -30,10 +26,6 @@ console.log(functionName)An object with the following properties:-### `layerArn`--The [ARN](https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html) of the Lambda Layer that should be used. You can obtain it by calling [`ensureLambdaBinaries()`](/docs/lambda/ensurelambdabinaries).-### `region`The [AWS region](/docs/lambda/region-selection) which you want to deploy the Lambda function too. It must be the same region that your Lambda Layer resides in.diff --git a/packages/docs/docs/ensurelambdabinaries.md b/packages/docs/docs/ensurelambdabinaries.mddeleted file mode 100644index 5b5841e8b6..0000000000--- a/packages/docs/docs/ensurelambdabinaries.md+++ /dev/null@@ -1,44 +0,0 @@-----id: ensurelambdabinaries-title: ensureLambdaBinaries()-slug: /lambda/ensurelambdabinaries------Ensures that a [Lambda layer](https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html) with the necessary binaries exists.--The Remotion lambda layer contains the binaries for FFMPEG and Chromium and is necessary for Remotion Lambda to work.--The binaries are downloaded from a Remotion-hosted S3 bucket and copied into your AWS account.--The binaries are hosted at the following URL:--```-https://lambda-remotion-binaries-<any-s3-region>.s3.<any-s3-region>.amazonaws.com/remotion.zip-```--This value is hardcoded into the `ensureLambdaBinaries()` function - you only need to call it.--## Example--```ts twoslash-// @module: esnext-// @target: es2017-import {ensureLambdaBinaries} from '@remotion/lambda';--// ...--const {layerArn} = await ensureLambdaBinaries('us-east-1');-console.log(layerArn)-```--## Arguments--### `region`--The AWS region in which you would like to install the binaries. You have to install the binaries separately for each region that you would like to use Remotion Lambda.--## Return value--An object with the following keys:--- `layerArn` _(string)_: The [ARN](https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html) of the layer that has been created, or if one has already existed, the ARN of the existing layer.diff --git a/packages/docs/docs/lambda-setup.md b/packages/docs/docs/lambda-setup.mdindex 19ddf87987..6e010a3e2d 100644--- a/packages/docs/docs/lambda-setup.md+++ b/packages/docs/docs/lambda-setup.md@@ -101,30 +101,15 @@ npx remotion lambda functions deploy</TabItem><TabItem value="node">-First create a Lambda layer - it will contain the necessary binaries such as Google Chrome and FFMPEG. If one already exists, it will be used instead.--We'll assume `us-east-1`, but you can choose [any supported region](/docs/lambda/region-selection).+You can deploy a function using [`deployFunction()`](/docs/lambda/deployfunction).```ts twoslash// @module: ESNext// @target: ESNext-import {ensureLambdaBinaries, deployFunction} from '@remotion/lambda';--const {layerArn} = await ensureLambdaBinaries('us-east-1')-```--Now you are ready to deploy the function itself using [`deployFunction()`](/docs/lambda/deployfunction).--```ts twoslash-// @module: ESNext-// @target: ESNext-import {ensureLambdaBinaries, deployFunction} from '@remotion/lambda';--const {layerArn} = await ensureLambdaBinaries('us-east-1')+import {deployFunction} from '@remotion/lambda';// ---cut---const {functionName} = await deployFunction({- layerArn,region: 'us-east-1',timeoutInSeconds: 120,memorySizeInMb: 1536diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.jsindex 6bf8c4b4d2..85155f67db 100644--- a/packages/docs/sidebars.js+++ b/packages/docs/sidebars.js@@ -24,7 +24,6 @@ module.exports = {"getfunctions","deletesite","deploysite",- "ensurelambdabinaries","getuserpolicy","getrolepolicy","getsites",diff --git a/packages/lambda/package.json b/packages/lambda/package.jsonindex 3d82d00fdb..f95a37ea8d 100644--- a/packages/lambda/package.json+++ b/packages/lambda/package.json@@ -30,7 +30,6 @@"aws-policies": "^1.0.1","dotenv": "^10.0.0","esbuild": "^0.11.12",- "lambdafs": "^2.0.3","minimist": "^1.2.5","p-limit": "^3.1.0","p-retry": "^4.6.0",diff --git a/packages/lambda/src/admin/make-layer-public.ts b/packages/lambda/src/admin/make-layer-public.tsindex c5431a51ba..36b1ac71a3 100644--- a/packages/lambda/src/admin/make-layer-public.ts+++ b/packages/lambda/src/admin/make-layer-public.ts@@ -1,17 +1,43 @@-import {AddLayerVersionPermissionCommand} from '@aws-sdk/client-lambda';+import {+ AddLayerVersionPermissionCommand,+ PublishLayerVersionCommand,+} from '@aws-sdk/client-lambda';import {lambda} from 'aws-policies';+import {AwsRegion} from '..';import {getLambdaClient} from '../shared/aws-clients';+import {CURRENT_VERSION} from '../shared/constants';++const runtimes: string[] = ['nodejs14.x'];+const region: AwsRegion = 'eu-central-1';export const makeLayerPublic = async () => {- await getLambdaClient('eu-central-1').send(- new AddLayerVersionPermissionCommand({- Action: lambda.GetLayerVersion,- LayerName: 'remotion-binaries',- Principal: '*',- VersionNumber: 9,- StatementId: 'public-layer',- })- );+ const layers = ['remotion', 'ffmpeg', 'chromium'];+ for (const layer of layers) {+ console.log({layer});+ const layerName = `remotion-binaries-${layer}`;+ const {Version} = await getLambdaClient(region).send(+ new PublishLayerVersionCommand({+ Content: {+ S3Bucket: 'lambda-remotion-binaries-' + region,+ S3Key: `remotion-layer-${layer}-v1.zip`,+ },+ LayerName: layerName,+ LicenseInfo:+ 'https://ffmpeg.org/legal.html / https://chromium.googlesource.com/chromium/src/+/refs/heads/main/LICENSE',+ CompatibleRuntimes: runtimes,+ Description: CURRENT_VERSION,+ })+ );+ await getLambdaClient('eu-central-1').send(+ new AddLayerVersionPermissionCommand({+ Action: lambda.GetLayerVersion,+ LayerName: layerName,+ Principal: '*',+ VersionNumber: Version,+ StatementId: 'public-layer',+ })+ );+ }};makeLayerPublic().then(() => {diff --git a/packages/lambda/src/api/__mocks__/create-function.ts b/packages/lambda/src/api/__mocks__/create-function.tsindex d8a14b667d..19d57e22ae 100644--- a/packages/lambda/src/api/__mocks__/create-function.ts+++ b/packages/lambda/src/api/__mocks__/create-function.ts@@ -1,13 +1,8 @@import {CURRENT_VERSION} from '../../defaults';import {createFunction as original} from '../create-function';import {addFunction} from '../mock-functions';-import {isLayerEnsured} from './mock-layers';export const createFunction: typeof original = async (input) => {- if (!isLayerEnsured(input.region)) {- throw new TypeError('did not ensure layer for ' + input.region);- }-addFunction({functionName: input.functionName,diff --git a/packages/lambda/src/api/__mocks__/ensure-lambda-binaries.ts b/packages/lambda/src/api/__mocks__/ensure-lambda-binaries.tsdeleted file mode 100644index bc752e5dad..0000000000--- a/packages/lambda/src/api/__mocks__/ensure-lambda-binaries.ts+++ /dev/null@@ -1,9 +0,0 @@-import {ensureLambdaBinaries as original} from '../ensure-lambda-binaries';-import {ensureLayer} from './mock-layers';--export const ensureLambdaBinaries: typeof original = (region) => {- ensureLayer(region);- return Promise.resolve({- layerArn: region,- });-};diff --git a/packages/lambda/src/api/__mocks__/mock-layers.ts b/packages/lambda/src/api/__mocks__/mock-layers.tsdeleted file mode 100644index 233f0f8e44..0000000000--- a/packages/lambda/src/api/__mocks__/mock-layers.ts+++ /dev/null@@ -1,9 +0,0 @@-export const layersEnsured: {[key: string]: boolean} = {};--export const ensureLayer = (layer: string) => {- layersEnsured[layer] = true;-};--export const isLayerEnsured = (layer: string): boolean => {- return Boolean(layersEnsured[layer]);-};diff --git a/packages/lambda/src/api/create-function.ts b/packages/lambda/src/api/create-function.tsindex 7352aeca66..691044a14d 100644--- a/packages/lambda/src/api/create-function.ts+++ b/packages/lambda/src/api/create-function.ts@@ -10,7 +10,6 @@ export const createFunction = async ({accountId,memorySizeInMb,timeoutInSeconds,- layerArn,}: {region: AwsRegion;zipFile: string;@@ -18,11 +17,11 @@ export const createFunction = async ({accountId: string;memorySizeInMb: number;timeoutInSeconds: number;- layerArn: string;}) => {const {FunctionName} = await getLambdaClient(region).send(new CreateFunctionCommand({Code: {+ // TODO: Put it in S3 bucketZipFile: readFileSync(zipFile),},FunctionName: functionName,@@ -33,7 +32,11 @@ export const createFunction = async ({Description: 'Renders a Remotion video.',MemorySize: memorySizeInMb,Timeout: timeoutInSeconds,- Layers: [layerArn],+ Layers: [+ `arn:aws:lambda:eu-central-1:976210361945:layer:remotion-binaries-chromium:1`,+ 'arn:aws:lambda:eu-central-1:976210361945:layer:remotion-binaries-ffmpeg:1',+ 'arn:aws:lambda:eu-central-1:976210361945:layer:remotion-binaries-remotion:1',+ ],}));return {FunctionName};diff --git a/packages/lambda/src/api/deploy-function.ts b/packages/lambda/src/api/deploy-function.tsindex 7d2569251b..f6606cbebf 100644--- a/packages/lambda/src/api/deploy-function.ts+++ b/packages/lambda/src/api/deploy-function.ts@@ -12,14 +12,12 @@ import {createFunction} from './create-function';* @description Creates an AWS Lambda function in your account that will be able to render a video in the cloud.* @link https://remotion.dev/docs/lambda/deployfunction* @param options.region The region you want to deploy your function to.- * @param options.layerArn The resource identifier of the Lambda layer. See documentation for this function on how to retrieve it.* @param options.timeoutInSeconds After how many seconds the lambda function should be killed if it does not end itself.* @param options.memorySizeInMb How much memory should be allocated to the Lambda function.* @returns An object that contains the `functionName` property*/export const deployFunction = async (options: {region: AwsRegion;- layerArn: string;timeoutInSeconds: number;memorySizeInMb: number;}) => {@@ -40,7 +38,6 @@ export const deployFunction = async (options: {accountId,memorySizeInMb: options.memorySizeInMb,timeoutInSeconds: options.timeoutInSeconds,- layerArn: options.layerArn,});if (!created.FunctionName) {diff --git a/packages/lambda/src/api/ensure-lambda-binaries.ts b/packages/lambda/src/api/ensure-lambda-binaries.tsdeleted file mode 100644index 58a99fac99..0000000000--- a/packages/lambda/src/api/ensure-lambda-binaries.ts+++ /dev/null@@ -1,90 +0,0 @@-import {- LambdaClient,- LayersListItem,- ListLayersCommand,- PublishLayerVersionCommand,-} from '@aws-sdk/client-lambda';-import {AwsRegion} from '../pricing/aws-regions';-import {getLambdaClient} from '../shared/aws-clients';-import {CURRENT_VERSION, getBinariesBucketName} from '../shared/constants';--const runtimes: string[] = ['nodejs14.x', 'nodejs12.x', 'nodejs10.x'];--const LAYER_NAME = 'remotion-binaries';--const createLayer = ({- region,- name,- key,- sourceS3Bucket,-}: {- region: AwsRegion;- name: string;- key: string;- sourceS3Bucket: string;-}) => {- return getLambdaClient(region).send(- new PublishLayerVersionCommand({- Content: {- S3Bucket: sourceS3Bucket,- S3Key: key,- },- LayerName: name,- LicenseInfo:- 'https://ffmpeg.org/legal.html / https://chromium.googlesource.com/chromium/src/+/refs/heads/main/LICENSE',- CompatibleRuntimes: runtimes,- Description: CURRENT_VERSION,- })- );-};--const getLayers = async (lambdaClient: LambdaClient) => {- const data = await lambdaClient.send(- new ListLayersCommand({- CompatibleRuntime: runtimes[0],- })- );- return (data.Layers || []) as LayersListItem[];-};--const hasLayer = (name: string, layers: LayersListItem[]) => {- return layers.find(- (l) =>- l.LayerName === name &&- l.LatestMatchingVersion?.Description === CURRENT_VERSION- );-};--const ensureLayer = async ({- layers,- region,-}: {- region: AwsRegion;- layers: LayersListItem[];-}): Promise<string> => {- const existingLayer = hasLayer(LAYER_NAME, layers);- if (existingLayer) {- return existingLayer.LatestMatchingVersion?.LayerVersionArn as string;- }-- const layer = await createLayer({- name: LAYER_NAME,- key: 'remotion.zip',- sourceS3Bucket: getBinariesBucketName(region),- region,- });- return layer.LayerVersionArn as string;-};--/**- * @description Ensures that a Lambda layer with the necessary binaries exists.- * @link https://remotion.dev/docs/lambda/ensurelambdabinaries- * @param {AwsRegion} region The region in which you want ensure the binaries are deployed.- * @returns `Promise<{layerArn: string}>`- */-export const ensureLambdaBinaries = async (region: AwsRegion) => {- const layers = await getLayers(getLambdaClient(region));- const layerArn = await ensureLayer({layers, region});-- return {layerArn};-};diff --git a/packages/lambda/src/cli/commands/functions/deploy.ts b/packages/lambda/src/cli/commands/functions/deploy.tsindex 2340455f43..12df23e74a 100644--- a/packages/lambda/src/cli/commands/functions/deploy.ts+++ b/packages/lambda/src/cli/commands/functions/deploy.ts@@ -1,7 +1,6 @@import {CliInternals} from '@remotion/cli';import {Log} from '@remotion/cli/dist/log';import {deployFunction} from '../../../api/deploy-function';-import {ensureLambdaBinaries} from '../../../api/ensure-lambda-binaries';import {CURRENT_VERSION,DEFAULT_MEMORY_SIZE,@@ -29,12 +28,10 @@ export const functionsDeploySubcommand = async () => {const output = CliInternals.createOverwriteableCliOutput();output.update('Ensuring Lambda binaries...');// TODO: Output can be more finegrained- const {layerArn} = await ensureLambdaBinaries(getAwsRegion());- output.update('Bundling lambda and deploying...');+ output.update('Deploying Lambda...');const {functionName} = await deployFunction({region,timeoutInSeconds,- layerArn,memorySizeInMb,});output.update(`Deployed to ${functionName}\n`);diff --git a/packages/lambda/src/functions/helpers/get-chromium-executable-path.ts b/packages/lambda/src/functions/helpers/get-chromium-executable-path.tsindex ea0f9a23d0..bc22b6569e 100644--- a/packages/lambda/src/functions/helpers/get-chromium-executable-path.ts+++ b/packages/lambda/src/functions/helpers/get-chromium-executable-path.ts@@ -1,30 +1,21 @@-import LambdaFS from 'lambdafs';-if (/^AWS_Lambda_nodejs(?:10|12|14)[.]x$/.test(process.env.AWS_EXECUTION_ENV ?? '') === true) {if (process.env.FONTCONFIG_PATH === undefined) {- process.env.FONTCONFIG_PATH = '/tmp/aws';+ process.env.FONTCONFIG_PATH = '/opt/aws';}if (process.env.LD_LIBRARY_PATH === undefined) {- process.env.LD_LIBRARY_PATH = '/tmp/aws/lib';- } else if (process.env.LD_LIBRARY_PATH.startsWith('/tmp/aws/lib') !== true) {+ process.env.LD_LIBRARY_PATH = '/opt/aws/lib';+ } else if (process.env.LD_LIBRARY_PATH.startsWith('/opt/aws/lib') !== true) {process.env.LD_LIBRARY_PATH = [- ...new Set(['/tmp/aws/lib', ...process.env.LD_LIBRARY_PATH.split(':')]),+ ...new Set(['/opt/aws/lib', ...process.env.LD_LIBRARY_PATH.split(':')]),].join(':');}}export const executablePath = async (): Promise<string> => {- const promises = [- LambdaFS.inflate('/opt/bin/chromium.br'),- LambdaFS.inflate('/opt/bin/swiftshader.tar.br'),- LambdaFS.inflate('/opt/bin/aws.tar.br'),- ];-- const result = await Promise.all(promises);- return result[0];+ return '/opt/bin/chromium';};diff --git a/packages/lambda/src/index.ts b/packages/lambda/src/index.tsindex 65be1af750..fb05de7724 100644--- a/packages/lambda/src/index.ts+++ b/packages/lambda/src/index.ts@@ -2,7 +2,6 @@ import {deleteFunction} from './api/delete-function';import {deleteSite} from './api/delete-site';import {deployFunction} from './api/deploy-function';import {deploySite} from './api/deploy-site';-import {ensureLambdaBinaries} from './api/ensure-lambda-binaries';import {getFunctionInfo} from './api/get-function-info';import {getFunctions} from './api/get-functions';import {getOrCreateBucket} from './api/get-or-create-bucket';@@ -23,7 +22,6 @@ export {deleteSite,deployFunction,deploySite,- ensureLambdaBinaries,getFunctions,getUserPolicy,getRolePolicy,diff --git a/packages/lambda/src/run.ts b/packages/lambda/src/run.tsindex 649c36206c..a98bdc12b8 100644--- a/packages/lambda/src/run.ts+++ b/packages/lambda/src/run.ts@@ -2,7 +2,6 @@ import {CliInternals} from '@remotion/cli';import path from 'path';import {deployFunction} from './api/deploy-function';import {deploySite} from './api/deploy-site';-import {ensureLambdaBinaries} from './api/ensure-lambda-binaries';import {getRemotionS3Buckets} from './api/get-buckets';import {getFunctions} from './api/get-functions';import {getOrCreateBucket} from './api/get-or-create-bucket';@@ -34,12 +33,10 @@ const getFnName = async (options: {if (DEPLOY) {await cleanupLambdas({region: options.region});// await cleanUpBuckets({s3client: s3Client});- const {layerArn} = await ensureLambdaBinaries(getAwsRegion());const {functionName} = await deployFunction({region: getAwsRegion(),timeoutInSeconds: 120,- layerArn,memorySizeInMb: 2048,});diff --git a/packages/lambda/src/shared/__mocks__/get-account-id.ts b/packages/lambda/src/shared/__mocks__/get-account-id.tsindex 2f99ad129f..43c1914300 100644--- a/packages/lambda/src/shared/__mocks__/get-account-id.ts+++ b/packages/lambda/src/shared/__mocks__/get-account-id.ts@@ -6,5 +6,5 @@ export const getAccountId: typeof original = () => {throw new Error('Cannot get account ID');}- return Promise.resolve(accountId);+ return Promise.resolve(accountId[1]);};diff --git a/packages/lambda/src/test/integration/deploy-function.test.ts b/packages/lambda/src/test/integration/deploy-function.test.tsindex b0f15ec97c..2a9bc80336 100644--- a/packages/lambda/src/test/integration/deploy-function.test.ts+++ b/packages/lambda/src/test/integration/deploy-function.test.ts@@ -1,6 +1,5 @@import {deleteFunction} from '../../api/delete-function';import {deployFunction} from '../../api/deploy-function';-import {ensureLambdaBinaries} from '../../api/ensure-lambda-binaries';import {getFunctions} from '../../api/get-functions';import {cleanFnStore,@@ -17,7 +16,6 @@ jest.mock('../../api/create-bucket');jest.mock('../../api/upload-dir');jest.mock('../../api/bucket-exists');jest.mock('../../api/clean-items');-jest.mock('../../api/ensure-lambda-binaries');jest.mock('../../api/create-function');jest.mock('../../api/delete-function');jest.mock('../../api/bundle-lambda');@@ -25,10 +23,7 @@ jest.mock('../../api/get-functions');jest.mock('../../shared/get-account-id');test('Should be able to deploy function', async () => {- const {layerArn} = await ensureLambdaBinaries('us-east-1');-const {functionName} = await deployFunction({- layerArn,memorySizeInMb: 2048,region: 'us-east-1',timeoutInSeconds: 120,@@ -36,23 +31,10 @@ test('Should be able to deploy function', async () => {expect(functionName).toBe('remotion-render-abcdef');});-test('Should not be able to deploy function if binaries were not ensured', async () => {- await expect(() =>- deployFunction({- layerArn: 'us-east-2',- memorySizeInMb: 2048,- region: 'us-east-2',- timeoutInSeconds: 120,- })- ).rejects.toThrow(/did not ensure layer for/);-});-test('Should be able to get the function afterwards', async () => {cleanFnStore();- const {layerArn} = await ensureLambdaBinaries('us-east-1');const {functionName} = await deployFunction({- layerArn,memorySizeInMb: 2048,region: 'us-east-1',timeoutInSeconds: 120,@@ -80,10 +62,8 @@ test('Should be able to get the function afterwards', async () => {test('Should be able to delete the function', async () => {cleanFnStore();- const {layerArn} = await ensureLambdaBinaries('us-east-1');const {functionName} = await deployFunction({- layerArn,memorySizeInMb: 2048,region: 'us-east-1',timeoutInSeconds: 120,@@ -102,10 +82,8 @@ test('Should be able to delete the function', async () => {test('Should be able to get the function afterwards', async () => {cleanFnStore();- const {layerArn} = await ensureLambdaBinaries('us-east-1');const {functionName} = await deployFunction({- layerArn,memorySizeInMb: 2048,region: 'us-east-1',timeoutInSeconds: 120,