🎥 Make videos programmatically with React
Add VPC config support for remotion lambda
Tiago Mello78f0d20e41d9
diff --git a/packages/lambda/src/api/create-function.ts b/packages/lambda/src/api/create-function.tsindex c51406cd50..b873474372 100644--- a/packages/lambda/src/api/create-function.ts+++ b/packages/lambda/src/api/create-function.ts@@ -8,6 +8,7 @@ import {PutFunctionEventInvokeConfigCommand,PutRuntimeManagementConfigCommand,TagResourceCommand,+ VpcConfig,} from '@aws-sdk/client-lambda';import type {LogLevel} from '@remotion/renderer';import {RenderInternals} from '@remotion/renderer';@@ -35,6 +36,8 @@ export const createFunction = async ({enableLambdaInsights,enableV5Runtime,logLevel,+ vpcSubnetIds,+ vpcSecurityGroupIds}: {createCloudWatchLogGroup: boolean;region: AwsRegion;@@ -50,6 +53,8 @@ export const createFunction = async ({enableLambdaInsights: boolean;enableV5Runtime: boolean;logLevel: LogLevel;+ vpcSubnetIds: string;+ vpcSecurityGroupIds: string;}): Promise<{FunctionName: string}> => {if (createCloudWatchLogGroup) {RenderInternals.Log.verbose(@@ -115,6 +120,14 @@ export const createFunction = async ({);}+ let vpcConfig: VpcConfig | undefined+ if (vpcSubnetIds && vpcSecurityGroupIds) {+ vpcConfig = {+ SubnetIds: vpcSubnetIds.split(','),+ SecurityGroupIds: vpcSecurityGroupIds.split(','),+ }+ }+RenderInternals.Log.verbose({indent: false, logLevel},'Deploying new Lambda function',@@ -139,6 +152,7 @@ export const createFunction = async ({EphemeralStorage: {Size: ephemerealStorageInMb,},+ VpcConfig: vpcConfig,}),);diff --git a/packages/lambda/src/api/deploy-function.ts b/packages/lambda/src/api/deploy-function.tsindex fe2c6d54bd..4784419b52 100644--- a/packages/lambda/src/api/deploy-function.ts+++ b/packages/lambda/src/api/deploy-function.ts@@ -35,6 +35,8 @@ type OptionalParameters = {indent: boolean;logLevel: LogLevel;enableV5Runtime: boolean;+ vpcSubnetIds: string | undefined;+ vpcSecurityGroupIds: string | undefined;};export type DeployFunctionInput = MandatoryParameters &@@ -93,6 +95,8 @@ export const internalDeployFunction = async (enableLambdaInsights: params.enableLambdaInsights ?? false,enableV5Runtime: params.enableV5Runtime,logLevel: params.logLevel,+ vpcSubnetIds: params.vpcSubnetIds as string,+ vpcSecurityGroupIds: params.vpcSecurityGroupIds as string,});if (!created.FunctionName) {@@ -132,6 +136,8 @@ export const deployFunction = ({indent,logLevel,enableV5Runtime,+ vpcSubnetIds,+ vpcSecurityGroupIds,...options}: DeployFunctionInput) => {const diskSizeInMb = options.diskSizeInMb ?? DEFAULT_EPHEMERAL_STORAGE_IN_MB;@@ -149,5 +155,7 @@ export const deployFunction = ({cloudWatchLogRetentionPeriodInDays,enableV5Runtime:enableV5Runtime ?? NoReactInternals.ENABLE_V5_BREAKING_CHANGES,+ vpcSubnetIds,+ vpcSecurityGroupIds,});};diff --git a/packages/lambda/src/cli/args.ts b/packages/lambda/src/cli/args.tsindex 140d9880f1..7b5cc815ec 100644--- a/packages/lambda/src/cli/args.ts+++ b/packages/lambda/src/cli/args.ts@@ -37,6 +37,8 @@ type LambdaCommandLineOptions = {['force-bucket-name']: string | undefined;[BrowserSafeApis.options.deleteAfterOption.cliFlag]: DeleteAfter | undefined;[BrowserSafeApis.options.folderExpiryOption.cliFlag]: boolean | undefined;+ ['vpc-subnet-ids']: string | undefined;+ ['vpc-security-group-ids']: string | undefined;};export const parsedLambdaCli = CliInternals.minimist<LambdaCommandLineOptions>(diff --git a/packages/lambda/src/cli/commands/functions/deploy.ts b/packages/lambda/src/cli/commands/functions/deploy.tsindex fefd67b78a..74bcb32c33 100644--- a/packages/lambda/src/cli/commands/functions/deploy.ts+++ b/packages/lambda/src/cli/commands/functions/deploy.ts@@ -12,6 +12,8 @@ import {validateCustomRoleArn} from '../../../shared/validate-custom-role-arn';import {validateDiskSizeInMb} from '../../../shared/validate-disk-size-in-mb';import {validateMemorySize} from '../../../shared/validate-memory-size';import {validateTimeout} from '../../../shared/validate-timeout';+import {validateVpcSubnetIds} from '../../../shared/validate-vpc-subnet-ids';+import {validateVpcSecurityGroupIds} from '../../../shared/validate-vpc-security-group-ids';import {parsedLambdaCli} from '../../args';import {getAwsRegion} from '../../get-aws-region';@@ -29,11 +31,15 @@ export const functionsDeploySubcommand = async (logLevel: LogLevel) => {const cloudWatchLogRetentionPeriodInDays =parsedLambdaCli['retention-period'] ?? DEFAULT_CLOUDWATCH_RETENTION_PERIOD;const enableV5Runtime = parsedLambdaCli['enable-v5-runtime'] ?? undefined;+ const vpcSubnetIds = parsedLambdaCli['vpc-subnet-ids'] ?? undefined;+ const vpcSecurityGroupIds = parsedLambdaCli['vpc-security-group-ids'] ?? undefined;validateMemorySize(memorySizeInMb);validateTimeout(timeoutInSeconds);validateDiskSizeInMb(diskSizeInMb);validateCustomRoleArn(customRoleArn);+ validateVpcSubnetIds(vpcSubnetIds);+ validateVpcSecurityGroupIds(vpcSecurityGroupIds);if (!CliInternals.quietFlagProvided()) {CliInternals.Log.info({indent: false, logLevel},@@ -47,6 +53,8 @@ Version = ${VERSION}CloudWatch Logging Enabled = ${createCloudWatchLogGroup}CloudWatch Retention Period = ${cloudWatchLogRetentionPeriodInDays} daysLambda Insights Enabled = ${enableLambdaInsights}+VPC Subnet IDs = ${vpcSubnetIds}+VPC Security Group IDs = ${vpcSecurityGroupIds}`.trim(),),);@@ -72,6 +80,8 @@ Lambda Insights Enabled = ${enableLambdaInsights}enableV5Runtime,indent: false,logLevel,+ vpcSubnetIds,+ vpcSecurityGroupIds,});if (CliInternals.quietFlagProvided()) {CliInternals.Log.info({indent: false, logLevel}, functionName);diff --git a/packages/lambda/src/shared/validate-vpc-security-group-ids.ts b/packages/lambda/src/shared/validate-vpc-security-group-ids.tsnew file mode 100644index 0000000000..655b8bc062--- /dev/null+++ b/packages/lambda/src/shared/validate-vpc-security-group-ids.ts@@ -0,0 +1,21 @@+export const validateVpcSecurityGroupIds = (vpcSecurityGroupIds: unknown) => {+ if (+ typeof vpcSecurityGroupIds !== 'undefined' &&+ typeof vpcSecurityGroupIds !== 'string' &&+ !isValidVpcSecurityGroupIdList(vpcSecurityGroupIds as string)+ ) {+ throw new TypeError(+ `parameter 'vpcSecurityGroupIds' must either be 'undefined' or a comma-separated list of VPC security group IDs string, but instead got: ${vpcSecurityGroupIds}`+ );+ }+};++const isValidVpcSecurityGroupIdList = (vpcSecurityGroupIds: string) => {+ const securityGroupIdRegex = /^sg-[0-9a-f]{17}$/;+ vpcSecurityGroupIds.split(',').forEach((securityGroupId) => {+ if (!securityGroupIdRegex.test(securityGroupId.trim())) {+ return false;+ }+ });+ return true;+};diff --git a/packages/lambda/src/shared/validate-vpc-subnet-ids.ts b/packages/lambda/src/shared/validate-vpc-subnet-ids.tsnew file mode 100644index 0000000000..4e1529882e--- /dev/null+++ b/packages/lambda/src/shared/validate-vpc-subnet-ids.ts@@ -0,0 +1,21 @@+export const validateVpcSubnetIds = (vpcSubnetIds: unknown) => {+ if (+ typeof vpcSubnetIds !== 'undefined' &&+ typeof vpcSubnetIds !== 'string' &&+ !isValidVpcSubnetIdList(vpcSubnetIds as string)+ ) {+ throw new TypeError(+ `parameter 'vpcSubnetIds' must either be 'undefined' or a comma-separated list of VPC subnet IDs string, but instead got: ${vpcSubnetIds}`+ );+ }+};++const isValidVpcSubnetIdList = (vpcSubnetIds: string) => {+ const subnetIdRegex = /^subnet-[0-9a-f]{17}$/;+ vpcSubnetIds.split(',').forEach((subnetId) => {+ if (!subnetIdRegex.test(subnetId.trim())) {+ return false;+ }+ });+ return true;+};