🎥 Make videos programmatically with React
`@remotion/lambda`: Allow custom Lambda function name, but warn about the consequences
Jonny Burgered1baa54cbf4
diff --git a/packages/lambda/src/api/speculate-function-name.ts b/packages/lambda/src/api/speculate-function-name.tsindex 59567de4d5..aedaf746d2 100644--- a/packages/lambda/src/api/speculate-function-name.ts+++ b/packages/lambda/src/api/speculate-function-name.ts@@ -20,6 +20,8 @@ export const speculateFunctionName = ({diskSizeInMb,timeoutInSeconds,}: SpeculateFunctionNameInput) => {+ // find-function-name.ts uses this for templating+ // consider this before adding any validation herereturn [`${RENDER_FN_PREFIX}${LAMBDA_VERSION_STRING}`,`mem${memorySizeInMb}mb`,diff --git a/packages/lambda/src/cli/helpers/find-function-name.ts b/packages/lambda/src/cli/helpers/find-function-name.tsindex a5fd172f30..fa0f33ea9f 100644--- a/packages/lambda/src/cli/helpers/find-function-name.ts+++ b/packages/lambda/src/cli/helpers/find-function-name.ts@@ -1,6 +1,7 @@import type {LogLevel, LogOptions} from '@remotion/renderer';import {VERSION} from 'remotion/version';import {getFunctions} from '../../api/get-functions';+import {speculateFunctionName} from '../../client';import {BINARY_NAME} from '../../shared/constants';import {parsedLambdaCli} from '../args';import {FUNCTIONS_COMMAND} from '../commands/functions';@@ -16,7 +17,7 @@ export const findFunctionName = async (logLevel: LogLevel) => {region: getAwsRegion(),compatibleOnly: false,});- let lambdasWithMatchingVersion = remotionLambdas.filter(+ const lambdasWithMatchingVersion = remotionLambdas.filter((l) => l.version === VERSION,);const logOptions: LogOptions = {@@ -24,6 +25,38 @@ export const findFunctionName = async (logLevel: LogLevel) => {logLevel,};+ const cliFlag = parsedLambdaCli['function-name'];++ if (cliFlag) {+ const compatibleFunctionExists = lambdasWithMatchingVersion.find(+ (l) => l.functionName === cliFlag,+ );+ if (!compatibleFunctionExists) {+ Log.warn(+ {indent: false, logLevel},+ `Function "${cliFlag}" does not match naming convention ${speculateFunctionName({diskSizeInMb: '[disk]', memorySizeInMb: '[memory]', timeoutInSeconds: '[timeout]'})}.`,+ );+ Log.warn(+ {indent: false, logLevel},+ 'Remotion relies on the naming to determine function information. This may lead to unexpected behavior.',+ );++ if (lambdasWithMatchingVersion.length > 0) {+ Log.info(logOptions, 'The following functions were found:');+ for (const l of lambdasWithMatchingVersion) {+ Log.info(logOptions, `- ${l.functionName} (v${l.version})`);+ }++ Log.info(+ logOptions,+ 'Prefer using one of those functions by passing their name to `--function-name` or removing it entirely.',+ );+ }++ return cliFlag;+ }+ }+if (lambdasWithMatchingVersion.length === 0) {Log.error({indent: false, logLevel},@@ -46,72 +79,34 @@ export const findFunctionName = async (logLevel: LogLevel) => {}if (lambdasWithMatchingVersion.length > 1) {- if (parsedLambdaCli['function-name']) {- const prevFunctions = [...lambdasWithMatchingVersion];- lambdasWithMatchingVersion = lambdasWithMatchingVersion.filter(- (l) => l.functionName === parsedLambdaCli['function-name'],- );- if (lambdasWithMatchingVersion.length === 0) {- Log.error(- {indent: false, logLevel},- `No Lambda function with name "${parsedLambdaCli['function-name']}" and version ${VERSION} found in your account.`,- );- Log.info(logOptions);-- if (prevFunctions.length === 0) {- Log.info(- logOptions,- `No functions for version ${VERSION} were found, deploy one using:`,- );- Log.info(- logOptions,- ` npx ${BINARY_NAME} ${FUNCTIONS_COMMAND} ${FUNCTIONS_DEPLOY_SUBCOMMAND}`,- );- quit(1);- }-- Log.info(logOptions, 'The following functions were found:');- for (const l of prevFunctions) {- Log.info(logOptions, `- ${l.functionName} (v${l.version})`);- }-- Log.info(- logOptions,- 'Remove the `--function-name` parameter use one of them.',- );-- quit(1);- }- } else {- Log.error(- {indent: false, logLevel},- 'More than 1 lambda function found in your account. Unsure which one to use.',- );- Log.info(logOptions);- Log.info(logOptions, 'Possible solutions:');- Log.info(- logOptions,- '- Define using `--function-name` which function you want to use.',- );- Log.info(- logOptions,- `- Delete extraneous lambda functions in your AWS console or using:`,- );- Log.info(- logOptions,- ` npx ${BINARY_NAME} ${FUNCTIONS_COMMAND} ${FUNCTIONS_RM_SUBCOMMAND} $(npx ${BINARY_NAME} ${FUNCTIONS_COMMAND} ${FUNCTIONS_LS_SUBCOMMAND} -q) -y`,- );- Log.info(logOptions);- Log.info(- logOptions,- `The following functions were found (only showing v${VERSION}):`,- );- for (const l of lambdasWithMatchingVersion) {- Log.info(logOptions, `- ${l.functionName}`);- }-- quit(1);+ Log.error(+ {indent: false, logLevel},+ 'More than 1 lambda function found in your account. Unsure which one to use.',+ );+ Log.info(logOptions);+ Log.info(logOptions, 'Possible solutions:');+ Log.info(+ logOptions,+ '- Define using `--function-name` which function you want to use.',+ );+ Log.info(+ logOptions,+ `- Delete extraneous lambda functions in your AWS console or using:`,+ );+ Log.info(+ logOptions,+ ` npx ${BINARY_NAME} ${FUNCTIONS_COMMAND} ${FUNCTIONS_RM_SUBCOMMAND} $(npx ${BINARY_NAME} ${FUNCTIONS_COMMAND} ${FUNCTIONS_LS_SUBCOMMAND} -q) -y`,+ );+ Log.info(logOptions);+ Log.info(+ logOptions,+ `The following functions were found (only showing v${VERSION}):`,+ );+ for (const l of lambdasWithMatchingVersion) {+ Log.info(logOptions, `- ${l.functionName}`);}++ quit(1);}const {functionName} = lambdasWithMatchingVersion[0];