Skip to content

🎥 Make videos programmatically with React

`@remotion/lambda`: Validate the input of `speculateFunctionName()`

Jonny Burger468c9122635d
diff --git a/packages/lambda-client/src/index.ts b/packages/lambda-client/src/index.ts
index 2e641aed59..8257d83e17 100644
--- a/packages/lambda-client/src/index.ts
+++ b/packages/lambda-client/src/index.ts
@@ -49,6 +49,7 @@ import {
renderMediaOnLambdaOptionalToRequired,
} from './render-media-on-lambda';
import {runtimePreferenceOptions} from './runtime-preference';
+import {innerSpeculateFunctionName} from './speculate-function-name';
import {validateAwsRegion} from './validate-aws-region';
import {parseBucketName} from './validate-bucketname';
import {validateDiskSizeInMb} from './validate-disk-size-in-mb';
@@ -144,4 +145,5 @@ export const LambdaClientInternals = {
cleanItems,
makeLambdaRenderStillPayload,
getRenderProgressPayload,
+ innerSpeculateFunctionName,
};
diff --git a/packages/lambda-client/src/speculate-function-name.ts b/packages/lambda-client/src/speculate-function-name.ts
index 105f9e5eb9..854038a544 100644
--- a/packages/lambda-client/src/speculate-function-name.ts
+++ b/packages/lambda-client/src/speculate-function-name.ts
@@ -7,17 +7,12 @@ export type SpeculateFunctionNameInput = {
timeoutInSeconds: string | number;
};
-/*
- * @description Speculate the name of the Lambda function that will be created by `deployFunction()` or its CLI equivalent, based on the function configuration.
- * @see [Documentation](https://remotion.dev/docs/lambda/speculatefunctionname)
- */
-export const speculateFunctionName = ({
- memorySizeInMb,
+export const innerSpeculateFunctionName = ({
diskSizeInMb,
+ memorySizeInMb,
timeoutInSeconds,
}: SpeculateFunctionNameInput) => {
- // find-function-name.ts uses this for templating
- // consider this before adding any validation here
+ // No validation here, used in find-function-name.ts
return [
`${RENDER_FN_PREFIX}${LAMBDA_VERSION_STRING}`,
`mem${memorySizeInMb}mb`,
@@ -25,3 +20,41 @@ export const speculateFunctionName = ({
`${timeoutInSeconds}sec`,
].join('-');
};
+
+/*
+ * @description Speculate the name of the Lambda function that will be created by `deployFunction()` or its CLI equivalent, based on the function configuration.
+ * @see [Documentation](https://remotion.dev/docs/lambda/speculatefunctionname)
+ */
+export const speculateFunctionName = ({
+ memorySizeInMb,
+ diskSizeInMb,
+ timeoutInSeconds,
+}: SpeculateFunctionNameInput) => {
+ const memorySize = Number(memorySizeInMb);
+ const diskSize = Number(diskSizeInMb);
+ const timeout = Number(timeoutInSeconds);
+
+ if (!Number.isInteger(memorySize) || memorySize <= 0) {
+ throw new Error(
+ `Memory size must be a positive integer. Received: ${memorySizeInMb}`,
+ );
+ }
+
+ if (!Number.isInteger(diskSize) || diskSize <= 0) {
+ throw new Error(
+ `Disk size must be a positive integer. Received: ${diskSizeInMb}`,
+ );
+ }
+
+ if (!Number.isInteger(timeout) || timeout <= 0) {
+ throw new Error(
+ `Timeout must be a positive integer. Received: ${timeoutInSeconds}`,
+ );
+ }
+
+ return innerSpeculateFunctionName({
+ diskSizeInMb,
+ memorySizeInMb,
+ timeoutInSeconds,
+ });
+};
diff --git a/packages/lambda/src/cli/helpers/find-function-name.ts b/packages/lambda/src/cli/helpers/find-function-name.ts
index b75e414957..e4d4513222 100644
--- a/packages/lambda/src/cli/helpers/find-function-name.ts
+++ b/packages/lambda/src/cli/helpers/find-function-name.ts
@@ -1,4 +1,4 @@
-import {AwsProvider, speculateFunctionName} from '@remotion/lambda-client';
+import {AwsProvider, LambdaClientInternals} from '@remotion/lambda-client';
import type {LogLevel, LogOptions} from '@remotion/renderer';
import {ProviderSpecifics} from '@remotion/serverless';
import {VERSION} from 'remotion/version';
@@ -40,7 +40,7 @@ export const findFunctionName = async ({
if (!compatibleFunctionExists) {
Log.warn(
{indent: false, logLevel},
- `Function "${cliFlag}" does not match naming convention ${speculateFunctionName({diskSizeInMb: '[disk]', memorySizeInMb: '[memory]', timeoutInSeconds: '[timeout]'})}.`,
+ `Function "${cliFlag}" does not match naming convention ${LambdaClientInternals.innerSpeculateFunctionName({diskSizeInMb: '[disk]', memorySizeInMb: '[memory]', timeoutInSeconds: '[timeout]'})}.`,
);
Log.warn(
{indent: false, logLevel},