🎥 Make videos programmatically with React
use hosted layers
Jonny Burgeref764cb69cc7
diff --git a/packages/lambda/src/admin/make-layer-public.ts b/packages/lambda/src/admin/make-layer-public.tsindex 90e487fdeb..f6e4441e24 100644--- a/packages/lambda/src/admin/make-layer-public.ts+++ b/packages/lambda/src/admin/make-layer-public.ts@@ -4,45 +4,94 @@ import {} from '@aws-sdk/client-lambda';import {lambda} from 'aws-policies';import {AwsRegion} from '..';+import {AWS_REGIONS} from '../regions';import {getLambdaClient} from '../shared/aws-clients';import {CURRENT_VERSION} from '../shared/constants';const runtimes: string[] = ['nodejs14.x'];-const region: AwsRegion = 'eu-central-1';++const layerInfo: {+ [region in AwsRegion]: {layerArn: string; version: number}[];+} = {+ 'af-south-1': [],+ 'ap-east-1': [],+ 'ap-northeast-1': [],+ 'ap-northeast-2': [],+ 'ap-northeast-3': [],+ 'ap-south-1': [],+ 'ap-southeast-1': [],+ 'ap-southeast-2': [],+ 'ca-central-1': [],+ 'eu-central-1': [],+ 'eu-north-1': [],+ 'eu-south-1': [],+ 'eu-west-1': [],+ 'eu-west-2': [],+ 'eu-west-3': [],+ 'me-south-1': [],+ 'sa-east-1': [],+ 'us-east-1': [],+ 'us-east-2': [],+ 'us-west-1': [],+ 'us-west-2': [],+};export const makeLayerPublic = async () => {- const layers = ['remotion', 'ffmpeg', 'chromium'];- for (const layer of layers) {- const layerName = `remotion-binaries-${layer}`;- const {Version, LayerArn} = 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',- })- );- console.log({LayerArn, Version});+ const layers = ['remotion', 'ffmpeg', 'chromium'] as const;+ for (const region of AWS_REGIONS) {+ for (const layer of layers) {+ const layerName = `remotion-binaries-${layer}`;+ const {Version, LayerArn} = await getLambdaClient(region).send(+ new PublishLayerVersionCommand({+ Content: {+ S3Bucket: 'lambda-remotion-binaries-' + region,+ S3Key: `remotion-layer-${layer}-v1.zip`,+ },+ LayerName: layerName,+ LicenseInfo:+ layer === 'chromium'+ ? 'Compiled from Chromium 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 UNIX .so files and Noto Sans font. Read Noto Sans License: https://fonts.google.com/noto/specimen/Noto+Sans/about',+ CompatibleRuntimes: runtimes,+ Description: CURRENT_VERSION,+ })+ );+ await getLambdaClient(region).send(+ new AddLayerVersionPermissionCommand({+ Action: lambda.GetLayerVersion,+ LayerName: layerName,+ Principal: '*',+ VersionNumber: Version,+ StatementId: 'public-layer',+ })+ );+ if (!layerInfo[region]) {+ layerInfo[region] = [];+ }++ if (!LayerArn) {+ throw new Error('layerArn is null');+ }++ if (!Version) {+ throw new Error('Version is null');+ }++ layerInfo[region].push({+ layerArn: LayerArn,+ version: Version,+ });+ console.log({LayerArn, Version});+ }}};makeLayerPublic().then(() => {- console.log('made public');+ console.log('\n\n\n\n\n');+ console.log(JSON.stringify(layerInfo, null, 2));}).catch((err) => {console.log(err);diff --git a/packages/lambda/src/api/create-function.ts b/packages/lambda/src/api/create-function.tsindex af7dceebf1..d67e9b5667 100644--- a/packages/lambda/src/api/create-function.ts+++ b/packages/lambda/src/api/create-function.ts@@ -2,6 +2,7 @@ import {CreateFunctionCommand} from '@aws-sdk/client-lambda';import {readFileSync} from 'fs';import {AwsRegion} from '..';import {getLambdaClient} from '../shared/aws-clients';+import {hostedLayers} from '../shared/hosted-layers';export const createFunction = async ({region,@@ -32,12 +33,9 @@ export const createFunction = async ({Description: 'Renders a Remotion video.',MemorySize: memorySizeInMb,Timeout: timeoutInSeconds,- Layers: [- // TODO: Unhardcode- 'arn:aws:lambda:eu-central-1:976210361945:layer:remotion-binaries-remotion:20',- 'arn:aws:lambda:eu-central-1:976210361945:layer:remotion-binaries-chromium:20',- 'arn:aws:lambda:eu-central-1:976210361945:layer:remotion-binaries-ffmpeg:20',- ],+ Layers: hostedLayers[region].map(+ ({layerArn, version}) => `${layerArn}:${version}`+ ),}));return {FunctionName};diff --git a/packages/lambda/src/shared/hosted-layers.ts b/packages/lambda/src/shared/hosted-layers.tsnew file mode 100644index 0000000000..84cd6f9e49--- /dev/null+++ b/packages/lambda/src/shared/hosted-layers.ts@@ -0,0 +1,366 @@+import {AwsRegion} from '..';++export const hostedLayers: {+ [key in AwsRegion]: {+ layerArn: string;+ version: number;+ }[];+} = {+ 'af-south-1': [+ {+ layerArn:+ 'arn:aws:lambda:af-south-1:976210361945:layer:remotion-binaries-remotion',+ version: 1,+ },+ {+ layerArn:+ 'arn:aws:lambda:af-south-1:976210361945:layer:remotion-binaries-ffmpeg',+ version: 1,+ },+ {+ layerArn:+ 'arn:aws:lambda:af-south-1:976210361945:layer:remotion-binaries-chromium',+ version: 1,+ },+ ],+ 'ap-east-1': [+ {+ layerArn:+ 'arn:aws:lambda:ap-east-1:976210361945:layer:remotion-binaries-remotion',+ version: 1,+ },+ {+ layerArn:+ 'arn:aws:lambda:ap-east-1:976210361945:layer:remotion-binaries-ffmpeg',+ version: 1,+ },+ {+ layerArn:+ 'arn:aws:lambda:ap-east-1:976210361945:layer:remotion-binaries-chromium',+ version: 1,+ },+ ],+ 'ap-northeast-1': [+ {+ layerArn:+ 'arn:aws:lambda:ap-northeast-1:976210361945:layer:remotion-binaries-remotion',+ version: 1,+ },+ {+ layerArn:+ 'arn:aws:lambda:ap-northeast-1:976210361945:layer:remotion-binaries-ffmpeg',+ version: 1,+ },+ {+ layerArn:+ 'arn:aws:lambda:ap-northeast-1:976210361945:layer:remotion-binaries-chromium',+ version: 1,+ },+ ],+ 'ap-northeast-2': [+ {+ layerArn:+ 'arn:aws:lambda:ap-northeast-2:976210361945:layer:remotion-binaries-remotion',+ version: 1,+ },+ {+ layerArn:+ 'arn:aws:lambda:ap-northeast-2:976210361945:layer:remotion-binaries-ffmpeg',+ version: 1,+ },+ {+ layerArn:+ 'arn:aws:lambda:ap-northeast-2:976210361945:layer:remotion-binaries-chromium',+ version: 1,+ },+ ],+ 'ap-northeast-3': [+ {+ layerArn:+ 'arn:aws:lambda:ap-northeast-3:976210361945:layer:remotion-binaries-remotion',+ version: 1,+ },+ {+ layerArn:+ 'arn:aws:lambda:ap-northeast-3:976210361945:layer:remotion-binaries-ffmpeg',+ version: 1,+ },+ {+ layerArn:+ 'arn:aws:lambda:ap-northeast-3:976210361945:layer:remotion-binaries-chromium',+ version: 1,+ },+ ],+ 'ap-south-1': [+ {+ layerArn:+ 'arn:aws:lambda:ap-south-1:976210361945:layer:remotion-binaries-remotion',+ version: 1,+ },+ {+ layerArn:+ 'arn:aws:lambda:ap-south-1:976210361945:layer:remotion-binaries-ffmpeg',+ version: 1,+ },+ {+ layerArn:+ 'arn:aws:lambda:ap-south-1:976210361945:layer:remotion-binaries-chromium',+ version: 1,+ },+ ],+ 'ap-southeast-1': [+ {+ layerArn:+ 'arn:aws:lambda:ap-southeast-1:976210361945:layer:remotion-binaries-remotion',+ version: 1,+ },+ {+ layerArn:+ 'arn:aws:lambda:ap-southeast-1:976210361945:layer:remotion-binaries-ffmpeg',+ version: 1,+ },+ {+ layerArn:+ 'arn:aws:lambda:ap-southeast-1:976210361945:layer:remotion-binaries-chromium',+ version: 1,+ },+ ],+ 'ap-southeast-2': [+ {+ layerArn:+ 'arn:aws:lambda:ap-southeast-2:976210361945:layer:remotion-binaries-remotion',+ version: 1,+ },+ {+ layerArn:+ 'arn:aws:lambda:ap-southeast-2:976210361945:layer:remotion-binaries-ffmpeg',+ version: 1,+ },+ {+ layerArn:+ 'arn:aws:lambda:ap-southeast-2:976210361945:layer:remotion-binaries-chromium',+ version: 1,+ },+ ],+ 'ca-central-1': [+ {+ layerArn:+ 'arn:aws:lambda:ca-central-1:976210361945:layer:remotion-binaries-remotion',+ version: 1,+ },+ {+ layerArn:+ 'arn:aws:lambda:ca-central-1:976210361945:layer:remotion-binaries-ffmpeg',+ version: 1,+ },+ {+ layerArn:+ 'arn:aws:lambda:ca-central-1:976210361945:layer:remotion-binaries-chromium',+ version: 1,+ },+ ],+ 'eu-central-1': [+ {+ layerArn:+ 'arn:aws:lambda:eu-central-1:976210361945:layer:remotion-binaries-remotion',+ version: 22,+ },+ {+ layerArn:+ 'arn:aws:lambda:eu-central-1:976210361945:layer:remotion-binaries-ffmpeg',+ version: 22,+ },+ {+ layerArn:+ 'arn:aws:lambda:eu-central-1:976210361945:layer:remotion-binaries-chromium',+ version: 22,+ },+ ],+ 'eu-north-1': [+ {+ layerArn:+ 'arn:aws:lambda:eu-north-1:976210361945:layer:remotion-binaries-remotion',+ version: 1,+ },+ {+ layerArn:+ 'arn:aws:lambda:eu-north-1:976210361945:layer:remotion-binaries-ffmpeg',+ version: 1,+ },+ {+ layerArn:+ 'arn:aws:lambda:eu-north-1:976210361945:layer:remotion-binaries-chromium',+ version: 1,+ },+ ],+ 'eu-south-1': [+ {+ layerArn:+ 'arn:aws:lambda:eu-south-1:976210361945:layer:remotion-binaries-remotion',+ version: 1,+ },+ {+ layerArn:+ 'arn:aws:lambda:eu-south-1:976210361945:layer:remotion-binaries-ffmpeg',+ version: 1,+ },+ {+ layerArn:+ 'arn:aws:lambda:eu-south-1:976210361945:layer:remotion-binaries-chromium',+ version: 1,+ },+ ],+ 'eu-west-1': [+ {+ layerArn:+ 'arn:aws:lambda:eu-west-1:976210361945:layer:remotion-binaries-remotion',+ version: 1,+ },+ {+ layerArn:+ 'arn:aws:lambda:eu-west-1:976210361945:layer:remotion-binaries-ffmpeg',+ version: 1,+ },+ {+ layerArn:+ 'arn:aws:lambda:eu-west-1:976210361945:layer:remotion-binaries-chromium',+ version: 1,+ },+ ],+ 'eu-west-2': [+ {+ layerArn:+ 'arn:aws:lambda:eu-west-2:976210361945:layer:remotion-binaries-remotion',+ version: 1,+ },+ {+ layerArn:+ 'arn:aws:lambda:eu-west-2:976210361945:layer:remotion-binaries-ffmpeg',+ version: 1,+ },+ {+ layerArn:+ 'arn:aws:lambda:eu-west-2:976210361945:layer:remotion-binaries-chromium',+ version: 1,+ },+ ],+ 'eu-west-3': [+ {+ layerArn:+ 'arn:aws:lambda:eu-west-3:976210361945:layer:remotion-binaries-remotion',+ version: 1,+ },+ {+ layerArn:+ 'arn:aws:lambda:eu-west-3:976210361945:layer:remotion-binaries-ffmpeg',+ version: 1,+ },+ {+ layerArn:+ 'arn:aws:lambda:eu-west-3:976210361945:layer:remotion-binaries-chromium',+ version: 1,+ },+ ],+ 'me-south-1': [+ {+ layerArn:+ 'arn:aws:lambda:me-south-1:976210361945:layer:remotion-binaries-remotion',+ version: 1,+ },+ {+ layerArn:+ 'arn:aws:lambda:me-south-1:976210361945:layer:remotion-binaries-ffmpeg',+ version: 1,+ },+ {+ layerArn:+ 'arn:aws:lambda:me-south-1:976210361945:layer:remotion-binaries-chromium',+ version: 1,+ },+ ],+ 'sa-east-1': [+ {+ layerArn:+ 'arn:aws:lambda:sa-east-1:976210361945:layer:remotion-binaries-remotion',+ version: 1,+ },+ {+ layerArn:+ 'arn:aws:lambda:sa-east-1:976210361945:layer:remotion-binaries-ffmpeg',+ version: 1,+ },+ {+ layerArn:+ 'arn:aws:lambda:sa-east-1:976210361945:layer:remotion-binaries-chromium',+ version: 1,+ },+ ],+ 'us-east-1': [+ {+ layerArn:+ 'arn:aws:lambda:us-east-1:976210361945:layer:remotion-binaries-remotion',+ version: 2,+ },+ {+ layerArn:+ 'arn:aws:lambda:us-east-1:976210361945:layer:remotion-binaries-ffmpeg',+ version: 2,+ },+ {+ layerArn:+ 'arn:aws:lambda:us-east-1:976210361945:layer:remotion-binaries-chromium',+ version: 2,+ },+ ],+ 'us-east-2': [+ {+ layerArn:+ 'arn:aws:lambda:us-east-2:976210361945:layer:remotion-binaries-remotion',+ version: 2,+ },+ {+ layerArn:+ 'arn:aws:lambda:us-east-2:976210361945:layer:remotion-binaries-ffmpeg',+ version: 2,+ },+ {+ layerArn:+ 'arn:aws:lambda:us-east-2:976210361945:layer:remotion-binaries-chromium',+ version: 2,+ },+ ],+ 'us-west-1': [+ {+ layerArn:+ 'arn:aws:lambda:us-west-1:976210361945:layer:remotion-binaries-remotion',+ version: 2,+ },+ {+ layerArn:+ 'arn:aws:lambda:us-west-1:976210361945:layer:remotion-binaries-ffmpeg',+ version: 2,+ },+ {+ layerArn:+ 'arn:aws:lambda:us-west-1:976210361945:layer:remotion-binaries-chromium',+ version: 2,+ },+ ],+ 'us-west-2': [+ {+ layerArn:+ 'arn:aws:lambda:us-west-2:976210361945:layer:remotion-binaries-remotion',+ version: 2,+ },+ {+ layerArn:+ 'arn:aws:lambda:us-west-2:976210361945:layer:remotion-binaries-ffmpeg',+ version: 2,+ },+ {+ layerArn:+ 'arn:aws:lambda:us-west-2:976210361945:layer:remotion-binaries-chromium',+ version: 2,+ },+ ],+};