🎥 Make videos programmatically with React
default architecture
Jonny Burgerad208e7992ff
diff --git a/packages/docs/components/lambda/default-architecture.tsx b/packages/docs/components/lambda/default-architecture.tsxnew file mode 100644index 0000000000..dd516081e6--- /dev/null+++ b/packages/docs/components/lambda/default-architecture.tsx@@ -0,0 +1,6 @@+import { DEFAULT_ARCHITECTURE } from "@remotion/lambda/dist/defaults";+import React from "react";++export const DefaultArchitecture: React.FC = () => {+ return <span>{DEFAULT_ARCHITECTURE}</span>;+};diff --git a/packages/docs/docs/lambda/cli/functions.md b/packages/docs/docs/lambda/cli/functions.mdindex 6f02334f46..0350b7fa17 100644--- a/packages/docs/docs/lambda/cli/functions.md+++ b/packages/docs/docs/lambda/cli/functions.md@@ -8,6 +8,7 @@ slug: /lambda/cli/functionsimport {DefaultMemorySize} from '../../../components/lambda/default-memory-size';import {DefaultTimeout} from '../../../components/lambda/default-timeout';import {DefaultLogRetention} from '../../../components/lambda/default-log-retention';+import {DefaultArchitecture} from '../../../components/lambda/default-architecture';The `npx remotion lambda functions` command allows you to deploy, view and delete AWS lambda functions that can render videos.@@ -58,6 +59,10 @@ Memory size in megabytes. Default: <DefaultMemorySize /> MB.Memory size in megabytes. Default: <DefaultTimeout /> seconds.+### `--architecture`++Retention period for the CloudWatch Logs in days. Default: <DefaultLogRetention /> days.+### `--disable-cloudwatch`Does not create a CloudWatch log group.diff --git a/packages/docs/docs/lambda/deployfunction.md b/packages/docs/docs/lambda/deployfunction.mdindex 20fa18312f..9bb68d617c 100644--- a/packages/docs/docs/lambda/deployfunction.md+++ b/packages/docs/docs/lambda/deployfunction.md@@ -42,6 +42,10 @@ We recommend a timeout of 120 seconds or lower - remember, Remotion Lambda is thHow many megabytes of RAM the Lambda function should have. By default we recommend a value of 1024MB. You may increase or decrease it depending on how memory-consuming your video is. The minimum allowed number is `512`, the maximum allowed number is `10240`. Since the costs of Remotion Lambda is directly proportional to the amount of RAM, we recommend to keep this amount as low as possible.+### `architecture`++Either `x86_64` or `arm64`.+### `createCloudWatchLogGroup`Whether logs should be saved into CloudWatch. We recommend enabling this option.diff --git a/packages/lambda/src/api/create-function.ts b/packages/lambda/src/api/create-function.tsindex 15a25f4fce..ac1c315d05 100644--- a/packages/lambda/src/api/create-function.ts+++ b/packages/lambda/src/api/create-function.ts@@ -7,10 +7,11 @@ import {PutFunctionEventInvokeConfigCommand,} from '@aws-sdk/client-lambda';import {readFileSync} from 'fs';-import { LOG_GROUP_PREFIX } from '../defaults';+import {LOG_GROUP_PREFIX} from '../defaults';import {AwsRegion} from '../pricing/aws-regions';import {getCloudWatchLogsClient, getLambdaClient} from '../shared/aws-clients';import {hostedLayers} from '../shared/hosted-layers';+import {LambdaArchitecture} from '../shared/validate-architecture';import {ROLE_NAME} from './iam-validation/suggested-policy';export const createFunction = async ({@@ -23,6 +24,7 @@ export const createFunction = async ({timeoutInSeconds,alreadyCreated,retentionInDays,+ architecture,}: {createCloudWatchLogGroup: boolean;region: AwsRegion;@@ -33,6 +35,7 @@ export const createFunction = async ({timeoutInSeconds: number;alreadyCreated: boolean;retentionInDays: number;+ architecture: LambdaArchitecture;}): Promise<{FunctionName: string}> => {if (createCloudWatchLogGroup) {try {@@ -75,7 +78,7 @@ export const createFunction = async ({Layers: hostedLayers[region].map(({layerArn, version}) => `${layerArn}:${version}`),- Architectures: ['arm64'],+ Architectures: [architecture],}));await getLambdaClient(region).send(diff --git a/packages/lambda/src/api/deploy-function.ts b/packages/lambda/src/api/deploy-function.tsindex 51ede54b8e..c25ce654e7 100644--- a/packages/lambda/src/api/deploy-function.ts+++ b/packages/lambda/src/api/deploy-function.ts@@ -7,6 +7,10 @@ import {} from '../shared/constants';import {FUNCTION_ZIP} from '../shared/function-zip-path';import {getAccountId} from '../shared/get-account-id';+import {+ LambdaArchitecture,+ validateArchitecture,+} from '../shared/validate-architecture';import {validateAwsRegion} from '../shared/validate-aws-region';import {validateMemorySize} from '../shared/validate-memory-size';import {validateCloudWatchRetentionPeriod} from '../shared/validate-retention-period';@@ -19,6 +23,7 @@ export type DeployFunctionInput = {region: AwsRegion;timeoutInSeconds: number;memorySizeInMb: number;+ architecture: LambdaArchitecture;};export type DeployFunctionOutput = {@@ -34,6 +39,7 @@ export type DeployFunctionOutput = {* @param options.region The region you want to deploy your function to.* @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.+ * @param options.architecture The architecture Lambda should run on. One of x86_64 and x64* @returns {Promise<DeployFunctionOutput>} An object that contains the `functionName` property*/export const deployFunction = async (@@ -43,6 +49,7 @@ export const deployFunction = async (validateTimeout(options.timeoutInSeconds);validateAwsRegion(options.region);validateCloudWatchRetentionPeriod(options.cloudWatchLogRetentionPeriodInDays);+ validateArchitecture(options.architecture);const fnNameRender = `${RENDER_FN_PREFIX}${CURRENT_VERSION}-${options.memorySizeInMb}mb-${options.timeoutInSeconds}sec`;const accountId = await getAccountId({region: options.region});@@ -71,6 +78,7 @@ export const deployFunction = async (options.cloudWatchLogRetentionPeriodInDays ??DEFAULT_CLOUDWATCH_RETENTION_PERIOD,alreadyCreated: Boolean(alreadyDeployed),+ architecture: options.architecture,});if (!created.FunctionName) {diff --git a/packages/lambda/src/cli/args.ts b/packages/lambda/src/cli/args.tsindex 1583ef0809..fdd6543efd 100644--- a/packages/lambda/src/cli/args.ts+++ b/packages/lambda/src/cli/args.ts@@ -2,6 +2,7 @@ import {CliInternals} from '@remotion/cli';import minimist from 'minimist';import {AwsRegion} from '../pricing/aws-regions';import {Privacy} from '../shared/constants';+import {LambdaArchitecture} from '../shared/validate-architecture';type LambdaCommandLineOptions = {help: boolean;@@ -20,6 +21,7 @@ type LambdaCommandLineOptions = {['disable-cloudwatch']: boolean;['max-retries']: number;['out-name']: string | undefined;+ ['architecture']: LambdaArchitecture;privacy: Privacy;};diff --git a/packages/lambda/src/cli/commands/functions/deploy.ts b/packages/lambda/src/cli/commands/functions/deploy.tsindex 48455d447c..72a0167656 100644--- a/packages/lambda/src/cli/commands/functions/deploy.ts+++ b/packages/lambda/src/cli/commands/functions/deploy.ts@@ -3,10 +3,12 @@ import {Log} from '@remotion/cli/dist/log';import {deployFunction} from '../../../api/deploy-function';import {CURRENT_VERSION,+ DEFAULT_ARCHITECTURE,DEFAULT_CLOUDWATCH_RETENTION_PERIOD,DEFAULT_MEMORY_SIZE,DEFAULT_TIMEOUT,} from '../../../shared/constants';+import {validateArchitecture} from '../../../shared/validate-architecture';import {validateMemorySize} from '../../../shared/validate-memory-size';import {validateTimeout} from '../../../shared/validate-timeout';import {parsedLambdaCli} from '../../args';@@ -18,12 +20,14 @@ export const functionsDeploySubcommand = async () => {const region = getAwsRegion();const timeoutInSeconds = parsedLambdaCli.timeout ?? DEFAULT_TIMEOUT;const memorySizeInMb = parsedLambdaCli.memory ?? DEFAULT_MEMORY_SIZE;+ const architecture = parsedLambdaCli.architecture ?? DEFAULT_ARCHITECTURE;const createCloudWatchLogGroup = !parsedLambdaCli['disable-cloudwatch'];const cloudWatchLogRetentionPeriodInDays =parsedLambdaCli['retention-period'] ?? DEFAULT_CLOUDWATCH_RETENTION_PERIOD;validateMemorySize(memorySizeInMb);validateTimeout(timeoutInSeconds);+ validateArchitecture(architecture);if (!CliInternals.quietFlagProvided()) {Log.info(CliInternals.chalk.gray(@@ -32,6 +36,7 @@ Region = ${region}Memory = ${memorySizeInMb}MBTimeout = ${timeoutInSeconds}secVersion = ${CURRENT_VERSION}+Architecture = ${architecture}CloudWatch Logging Enabled = ${createCloudWatchLogGroup}CloudWatch Retention Period = ${cloudWatchLogRetentionPeriodInDays} days`.trim()@@ -49,6 +54,7 @@ CloudWatch Retention Period = ${cloudWatchLogRetentionPeriodInDays} daystimeoutInSeconds,memorySizeInMb,cloudWatchLogRetentionPeriodInDays,+ architecture,});if (CliInternals.quietFlagProvided()) {Log.info(functionName);diff --git a/packages/lambda/src/shared/constants.ts b/packages/lambda/src/shared/constants.tsindex ada9ed9c8b..9b5c91aac4 100644--- a/packages/lambda/src/shared/constants.ts+++ b/packages/lambda/src/shared/constants.ts@@ -11,6 +11,7 @@ import {import {ChunkRetry} from '../functions/helpers/get-retry-stats';import {EnhancedErrorInfo} from '../functions/helpers/write-lambda-error';import {AwsRegion} from '../pricing/aws-regions';+import {LambdaArchitecture} from './validate-architecture';// 10 minutes at 30fpsexport const MAX_VIDEO_LENGTH = 18000;@@ -19,6 +20,8 @@ export const MIN_MEMORY = 512;export const MAX_MEMORY = 10240;export const DEFAULT_MEMORY_SIZE = 2048;+export const DEFAULT_ARCHITECTURE: LambdaArchitecture = 'arm64';+export const DEFAULT_TIMEOUT = 120;export const MIN_TIMEOUT = 15;export const MAX_TIMEOUT = 900;diff --git a/packages/lambda/src/shared/validate-architecture.ts b/packages/lambda/src/shared/validate-architecture.tsnew file mode 100644index 0000000000..bdddf55d97--- /dev/null+++ b/packages/lambda/src/shared/validate-architecture.ts@@ -0,0 +1,18 @@+const validArchitectures = ['arm64', 'x86_64'] as const;++export type LambdaArchitecture = typeof validArchitectures[number];++export const validateArchitecture = (architecture: unknown) => {+ if (typeof architecture !== 'string') {+ throw new TypeError(+ 'You must pass an architecture when deploying: One of ' ++ validArchitectures.join(', ')+ );+ }++ if (validArchitectures.find((a) => a === architecture)) {+ throw new TypeError(+ `You must pass an "architecture" when deploying a function: either "arm64" or "x86_64"`+ );+ }+};diff --git a/packages/lambda/src/test/integration/deploy-function.test.ts b/packages/lambda/src/test/integration/deploy-function.test.tsindex 3de9c2b2b7..a250fd4ba5 100644--- a/packages/lambda/src/test/integration/deploy-function.test.ts+++ b/packages/lambda/src/test/integration/deploy-function.test.ts@@ -16,6 +16,7 @@ test('Should be able to deploy function', async () => {region: 'us-east-1',timeoutInSeconds: 120,createCloudWatchLogGroup: true,+ architecture: 'arm64',});expect(functionName).toBe(expectedFunctionName(2048, 120));});@@ -28,6 +29,7 @@ test('Should be able to get the function afterwards', async () => {region: 'us-east-1',timeoutInSeconds: 120,createCloudWatchLogGroup: true,+ architecture: 'arm64',});expect(functionName).toBe(expectedFunctionName(2048, 120));const fns = await getFunctions({@@ -58,6 +60,7 @@ test('Should be able to delete the function', async () => {region: 'us-east-1',timeoutInSeconds: 120,createCloudWatchLogGroup: true,+ architecture: 'arm64',});expect(functionName).toBe(expectedFunctionName(2048, 120));await deleteFunction({@@ -79,6 +82,7 @@ test('Should be able to get the function afterwards', async () => {region: 'us-east-1',timeoutInSeconds: 120,createCloudWatchLogGroup: true,+ architecture: 'arm64',});expect(functionName).toBe(expectedFunctionName(2048, 120));const fns = await getFunctions({