Skip to content

Commit 4ad8604

Browse files
committed
Merge branch 'main' into compositor-dont-panic-on-last-position
2 parents 839cf0f + 8fdda30 commit 4ad8604

File tree

5 files changed

+53
-14
lines changed

5 files changed

+53
-14
lines changed

packages/lambda-client/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import {
4949
renderMediaOnLambdaOptionalToRequired,
5050
} from './render-media-on-lambda';
5151
import {runtimePreferenceOptions} from './runtime-preference';
52+
import {innerSpeculateFunctionName} from './speculate-function-name';
5253
import {validateAwsRegion} from './validate-aws-region';
5354
import {parseBucketName} from './validate-bucketname';
5455
import {validateDiskSizeInMb} from './validate-disk-size-in-mb';
@@ -144,4 +145,5 @@ export const LambdaClientInternals = {
144145
cleanItems,
145146
makeLambdaRenderStillPayload,
146147
getRenderProgressPayload,
148+
innerSpeculateFunctionName,
147149
};

packages/lambda-client/src/speculate-function-name.ts

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,54 @@ export type SpeculateFunctionNameInput = {
77
timeoutInSeconds: string | number;
88
};
99

10-
/*
11-
* @description Speculate the name of the Lambda function that will be created by `deployFunction()` or its CLI equivalent, based on the function configuration.
12-
* @see [Documentation](https://remotion.dev/docs/lambda/speculatefunctionname)
13-
*/
14-
export const speculateFunctionName = ({
15-
memorySizeInMb,
10+
export const innerSpeculateFunctionName = ({
1611
diskSizeInMb,
12+
memorySizeInMb,
1713
timeoutInSeconds,
1814
}: SpeculateFunctionNameInput) => {
19-
// find-function-name.ts uses this for templating
20-
// consider this before adding any validation here
15+
// No validation here, used in find-function-name.ts
2116
return [
2217
`${RENDER_FN_PREFIX}${LAMBDA_VERSION_STRING}`,
2318
`mem${memorySizeInMb}mb`,
2419
`disk${diskSizeInMb}mb`,
2520
`${timeoutInSeconds}sec`,
2621
].join('-');
2722
};
23+
24+
/*
25+
* @description Speculate the name of the Lambda function that will be created by `deployFunction()` or its CLI equivalent, based on the function configuration.
26+
* @see [Documentation](https://remotion.dev/docs/lambda/speculatefunctionname)
27+
*/
28+
export const speculateFunctionName = ({
29+
memorySizeInMb,
30+
diskSizeInMb,
31+
timeoutInSeconds,
32+
}: SpeculateFunctionNameInput) => {
33+
const memorySize = Number(memorySizeInMb);
34+
const diskSize = Number(diskSizeInMb);
35+
const timeout = Number(timeoutInSeconds);
36+
37+
if (!Number.isInteger(memorySize) || memorySize <= 0) {
38+
throw new Error(
39+
`Memory size must be a positive integer. Received: ${memorySizeInMb}`,
40+
);
41+
}
42+
43+
if (!Number.isInteger(diskSize) || diskSize <= 0) {
44+
throw new Error(
45+
`Disk size must be a positive integer. Received: ${diskSizeInMb}`,
46+
);
47+
}
48+
49+
if (!Number.isInteger(timeout) || timeout <= 0) {
50+
throw new Error(
51+
`Timeout must be a positive integer. Received: ${timeoutInSeconds}`,
52+
);
53+
}
54+
55+
return innerSpeculateFunctionName({
56+
diskSizeInMb,
57+
memorySizeInMb,
58+
timeoutInSeconds,
59+
});
60+
};

packages/lambda/src/cli/helpers/find-function-name.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {AwsProvider, speculateFunctionName} from '@remotion/lambda-client';
1+
import {AwsProvider, LambdaClientInternals} from '@remotion/lambda-client';
22
import type {LogLevel, LogOptions} from '@remotion/renderer';
33
import {ProviderSpecifics} from '@remotion/serverless';
44
import {VERSION} from 'remotion/version';
@@ -40,7 +40,7 @@ export const findFunctionName = async ({
4040
if (!compatibleFunctionExists) {
4141
Log.warn(
4242
{indent: false, logLevel},
43-
`Function "${cliFlag}" does not match naming convention ${speculateFunctionName({diskSizeInMb: '[disk]', memorySizeInMb: '[memory]', timeoutInSeconds: '[timeout]'})}.`,
43+
`Function "${cliFlag}" does not match naming convention ${LambdaClientInternals.innerSpeculateFunctionName({diskSizeInMb: '[disk]', memorySizeInMb: '[memory]', timeoutInSeconds: '[timeout]'})}.`,
4444
);
4545
Log.warn(
4646
{indent: false, logLevel},

packages/template-next-app-tailwind/src/app/api/lambda/progress/route.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import {
33
AwsRegion,
44
getRenderProgress,
55
} from "@remotion/lambda/client";
6-
import { TIMEOUT } from "dns";
7-
import { DISK, RAM, REGION } from "../../../../../config.mjs";
6+
import { DISK, RAM, REGION, TIMEOUT } from "../../../../../config.mjs";
87
import { ProgressResponse, ProgressRequest } from "../../../../../types/schema";
98
import { executeApi } from "../../../../helpers/api-response";
109

packages/template-next-app/src/app/api/lambda/render/route.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ import {
44
speculateFunctionName,
55
} from "@remotion/lambda/client";
66
import { executeApi } from "../../../../helpers/api-response";
7-
import { TIMEOUT } from "dns";
8-
import { DISK, RAM, REGION, SITE_NAME } from "../../../../../config.mjs";
7+
import {
8+
DISK,
9+
RAM,
10+
REGION,
11+
SITE_NAME,
12+
TIMEOUT,
13+
} from "../../../../../config.mjs";
914
import { RenderRequest } from "../../../../types/schema";
1015

1116
export const POST = executeApi<RenderMediaOnLambdaOutput, typeof RenderRequest>(

0 commit comments

Comments
 (0)