Skip to content

🎥 Make videos programmatically with React

hmm

Jonny Burgerc6c53d63f0a5
diff --git a/packages/lambda/src/api/__mocks__/get-functions.ts b/packages/lambda/src/api/__mocks__/get-functions.ts
deleted file mode 100644
index 3e232d6889..0000000000
--- a/packages/lambda/src/api/__mocks__/get-functions.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-import {VERSION} from 'remotion/version';
-import type {getFunctions as original} from '../get-functions';
-import {getAllMockFunctions} from '../mock-functions';
-
-export const getFunctions: typeof original = ({region, compatibleOnly}) => {
- return Promise.resolve(
- getAllMockFunctions(region, compatibleOnly ? VERSION : null),
- );
-};
diff --git a/packages/lambda/src/api/delete-function.ts b/packages/lambda/src/api/delete-function.ts
index 6a9d467421..6ca61c2a6c 100644
--- a/packages/lambda/src/api/delete-function.ts
+++ b/packages/lambda/src/api/delete-function.ts
@@ -1,17 +1,18 @@
import {DeleteFunctionCommand} from '@aws-sdk/client-lambda';
-import type {AwsRegion} from '../regions';
+import type {
+ DeleteFunction,
+ DeleteFunctionInput as GenericDeleteFunctionInput,
+} from '@remotion/serverless';
+import type {AwsProvider} from '../functions/aws-implementation';
import {getLambdaClient} from '../shared/aws-clients';
-export type DeleteFunctionInput = {
- region: AwsRegion;
- functionName: string;
-};
+export type DeleteFunctionInput = GenericDeleteFunctionInput<AwsProvider>;
/*
* @description Deletes a deployed Lambda function based on its name.
* @see [Documentation](https://remotion.dev/docs/lambda/deletefunction)
*/
-export const deleteFunction = async ({
+export const deleteFunction: DeleteFunction<AwsProvider> = async ({
region,
functionName,
}: DeleteFunctionInput): Promise<void> => {
diff --git a/packages/lambda/src/api/deploy-function.ts b/packages/lambda/src/api/deploy-function.ts
index 25b6a26d90..438629c000 100644
--- a/packages/lambda/src/api/deploy-function.ts
+++ b/packages/lambda/src/api/deploy-function.ts
@@ -8,14 +8,12 @@ import type {AwsRegion} from '../regions';
import {
DEFAULT_CLOUDWATCH_RETENTION_PERIOD,
DEFAULT_EPHEMERAL_STORAGE_IN_MB,
- RENDER_FN_PREFIX,
} from '../shared/constants';
import {FUNCTION_ZIP_ARM64} from '../shared/function-zip-path';
import {
validateRuntimePreference,
type RuntimePreference,
} from '../shared/get-layers';
-import {LAMBDA_VERSION_STRING} from '../shared/lambda-version-string';
import {validateAwsRegion} from '../shared/validate-aws-region';
import {validateCustomRoleArn} from '../shared/validate-custom-role-arn';
import {validateDiskSizeInMb} from '../shared/validate-disk-size-in-mb';
@@ -23,6 +21,7 @@ import {validateMemorySize} from '../shared/validate-memory-size';
import {validateCloudWatchRetentionPeriod} from '../shared/validate-retention-period';
import {validateTimeout} from '../shared/validate-timeout';
import {createFunction} from './create-function';
+import {speculateFunctionName} from './speculate-function-name';
type MandatoryParameters = {
createCloudWatchLogGroup: boolean;
@@ -65,12 +64,11 @@ export const internalDeployFunction = async <Provider extends CloudProvider>(
validateCustomRoleArn(params.customRoleArn);
validateRuntimePreference(params.runtimePreference);
- const fnNameRender = [
- `${RENDER_FN_PREFIX}${LAMBDA_VERSION_STRING}`,
- `mem${params.memorySizeInMb}mb`,
- `disk${params.diskSizeInMb}mb`,
- `${params.timeoutInSeconds}sec`,
- ].join('-');
+ const functionName = speculateFunctionName({
+ diskSizeInMb: params.diskSizeInMb,
+ memorySizeInMb: params.memorySizeInMb,
+ timeoutInSeconds: params.timeoutInSeconds,
+ });
const accountId = await params.providerSpecifics.getAccountId({
region: params.region,
});
@@ -92,7 +90,7 @@ export const internalDeployFunction = async <Provider extends CloudProvider>(
createCloudWatchLogGroup: params.createCloudWatchLogGroup,
region: params.region,
zipFile: FUNCTION_ZIP_ARM64,
- functionName: fnNameRender,
+ functionName,
accountId,
memorySizeInMb: params.memorySizeInMb,
timeoutInSeconds: params.timeoutInSeconds,
diff --git a/packages/lambda/src/api/get-function-info.ts b/packages/lambda/src/api/get-function-info.ts
index f1f3f63196..2c1f55803f 100644
--- a/packages/lambda/src/api/get-function-info.ts
+++ b/packages/lambda/src/api/get-function-info.ts
@@ -1,19 +1,12 @@
import {GetFunctionCommand} from '@aws-sdk/client-lambda';
import type {LogLevel} from '@remotion/renderer';
+import type {FunctionInfo} from '@remotion/serverless';
import type {AwsRegion} from '../regions';
import {getLambdaClient} from '../shared/aws-clients';
import {DEFAULT_EPHEMERAL_STORAGE_IN_MB} from '../shared/constants';
import {getFunctionVersion} from '../shared/get-function-version';
import {validateAwsRegion} from '../shared/validate-aws-region';
-export type FunctionInfo = {
- functionName: string;
- timeoutInSeconds: number;
- memorySizeInMb: number;
- version: string | null;
- diskSizeInMb: number;
-};
-
export type GetFunctionInfoInput = {
region: AwsRegion;
functionName: string;
diff --git a/packages/lambda/src/api/get-functions.ts b/packages/lambda/src/api/get-functions.ts
index 4c9494ae9f..a1f13c6862 100644
--- a/packages/lambda/src/api/get-functions.ts
+++ b/packages/lambda/src/api/get-functions.ts
@@ -1,6 +1,7 @@
import type {FunctionConfiguration} from '@aws-sdk/client-lambda';
import {ListFunctionsCommand} from '@aws-sdk/client-lambda';
import type {LogLevel} from '@remotion/renderer';
+import type {FunctionInfo} from '@remotion/serverless';
import {VERSION} from 'remotion/version';
import type {AwsRegion} from '../regions';
import {getLambdaClient} from '../shared/aws-clients';
@@ -9,7 +10,6 @@ import {
RENDER_FN_PREFIX,
} from '../shared/constants';
import {getFunctionVersion} from '../shared/get-function-version';
-import type {FunctionInfo} from './get-function-info';
export type GetFunctionsInput = {
region: AwsRegion;
diff --git a/packages/lambda/src/api/mock-functions.ts b/packages/lambda/src/api/mock-functions.ts
index 789803ddbf..563b473166 100644
--- a/packages/lambda/src/api/mock-functions.ts
+++ b/packages/lambda/src/api/mock-functions.ts
@@ -1,5 +1,11 @@
+import type {
+ DeleteFunction,
+ FunctionInfo,
+ GetFunctions,
+} from '@remotion/serverless';
+import {VERSION} from 'remotion/version';
+import type {AwsProvider} from '../functions/aws-implementation';
import type {AwsRegion} from '../regions';
-import type {FunctionInfo} from './get-function-info';
export let mockFunctionsStore: (FunctionInfo & {
region: AwsRegion;
@@ -14,10 +20,14 @@ export const addFunction = (fn: FunctionInfo, region: AwsRegion) => {
});
};
-export const deleteMockFunction = (name: string, region: string) => {
+export const deleteMockFunction: DeleteFunction<AwsProvider> = ({
+ functionName,
+ region,
+}) => {
mockFunctionsStore = mockFunctionsStore.filter(
- (fn) => fn.functionName !== name && fn.region !== region,
+ (fn) => fn.functionName !== functionName && fn.region !== region,
);
+ return Promise.resolve();
};
export const findFunction = (name: string, region: string) => {
@@ -26,9 +36,15 @@ export const findFunction = (name: string, region: string) => {
);
};
-export const getAllMockFunctions = (region: string, version: string | null) => {
- return mockFunctionsStore.filter(
- (f) => f.region === region && (version ? f.version === version : true),
+export const getAllMockFunctions: GetFunctions<AwsProvider> = ({
+ compatibleOnly,
+ region,
+}) => {
+ return Promise.resolve(
+ mockFunctionsStore.filter(
+ (f) =>
+ f.region === region && (compatibleOnly ? f.version === VERSION : true),
+ ),
);
};
diff --git a/packages/lambda/src/functions/aws-implementation.ts b/packages/lambda/src/functions/aws-implementation.ts
index ea1a8aa345..81d8a0fcae 100644
--- a/packages/lambda/src/functions/aws-implementation.ts
+++ b/packages/lambda/src/functions/aws-implementation.ts
@@ -3,8 +3,10 @@ import {expiryDays} from '@remotion/serverless/client';
import {EventEmitter} from 'node:events';
import {bucketExistsInRegionImplementation} from '../api/bucket-exists';
import {createBucket} from '../api/create-bucket';
+import {deleteFunction} from '../api/delete-function';
import {estimatePrice} from '../api/estimate-price';
import {getRemotionBuckets} from '../api/get-buckets';
+import {getFunctions} from '../api/get-functions';
import {MAX_EPHEMERAL_STORAGE_IN_MB} from '../defaults';
import {lambdaDeleteFileImplementation} from '../io/delete-file';
import {lambdaHeadFileImplementation} from '../io/head-file';
@@ -119,4 +121,6 @@ export const awsImplementation: ProviderSpecifics<AwsProvider> = {
getMaxStillInlinePayloadSize: () => 5_000_000,
getMaxNonInlinePayloadSizePerFunction: () => 200_000,
getAccountId: getAccountIdImplementation,
+ deleteFunction,
+ getFunctions,
};
diff --git a/packages/lambda/src/index.ts b/packages/lambda/src/index.ts
index 574d0aa912..5fa82077f1 100644
--- a/packages/lambda/src/index.ts
+++ b/packages/lambda/src/index.ts
@@ -1,4 +1,8 @@
-import type {EnhancedErrorInfo, LambdaErrorInfo} from '@remotion/serverless';
+import type {
+ EnhancedErrorInfo,
+ FunctionInfo,
+ LambdaErrorInfo,
+} from '@remotion/serverless';
import type {
CustomCredentials,
GetOrCreateBucketInput,
@@ -32,7 +36,7 @@ import type {
GetCompositionsOnLambdaOutput,
} from './api/get-compositions-on-lambda';
import {getCompositionsOnLambda} from './api/get-compositions-on-lambda';
-import type {FunctionInfo, GetFunctionInfoInput} from './api/get-function-info';
+import type {GetFunctionInfoInput} from './api/get-function-info';
import {getFunctionInfo} from './api/get-function-info';
import type {GetFunctionsInput} from './api/get-functions';
import {getFunctions} from './api/get-functions';
@@ -73,6 +77,7 @@ import {
} from './internals';
import type {AwsRegion} from './regions';
import type {RenderProgress} from './shared/constants';
+
export type {WebhookPayload} from '@remotion/serverless';
/**
diff --git a/packages/lambda/src/test/integration/deploy-function.test.ts b/packages/lambda/src/test/integration/deploy-function.test.ts
index 197325ae97..d761dd2ea9 100644
--- a/packages/lambda/src/test/integration/deploy-function.test.ts
+++ b/packages/lambda/src/test/integration/deploy-function.test.ts
@@ -1,10 +1,8 @@
import {VERSION} from 'remotion/version';
import {expect, test} from 'vitest';
import {internalDeployFunction} from '../../api/deploy-function';
-import {getFunctions} from '../../api/get-functions';
import {
cleanFnStore,
- deleteMockFunction,
markFunctionAsIncompatible,
} from '../../api/mock-functions';
import {DEFAULT_EPHEMERAL_STORAGE_IN_MB} from '../../shared/constants';
@@ -58,7 +56,7 @@ test('Should be able to get the function afterwards', async () => {
expect(functionName).toBe(
expectedFunctionName(2048, 120, DEFAULT_EPHEMERAL_STORAGE_IN_MB),
);
- const fns = await getFunctions({
+ const fns = await mockImplementation.getFunctions({
region: 'us-east-1',
compatibleOnly: true,
});
@@ -76,7 +74,7 @@ test('Should be able to get the function afterwards', async () => {
diskSizeInMb: 2048,
},
]);
- const foreignFunctions = await getFunctions({
+ const foreignFunctions = await mockImplementation.getFunctions({
region: 'us-east-2',
compatibleOnly: true,
});
@@ -105,11 +103,15 @@ test('Should be able to delete the function', async () => {
expect(functionName).toBe(
expectedFunctionName(2048, 120, DEFAULT_EPHEMERAL_STORAGE_IN_MB),
);
- deleteMockFunction(
- expectedFunctionName(2048, 120, DEFAULT_EPHEMERAL_STORAGE_IN_MB),
- 'us-east-1',
- );
- const fns = await getFunctions({
+ mockImplementation.deleteFunction({
+ region: 'us-east-1',
+ functionName: expectedFunctionName(
+ 2048,
+ 120,
+ DEFAULT_EPHEMERAL_STORAGE_IN_MB,
+ ),
+ });
+ const fns = await mockImplementation.getFunctions({
region: 'us-east-1',
compatibleOnly: true,
});
@@ -138,7 +140,7 @@ test('Should be able to get the function afterwards', async () => {
expect(functionName).toBe(
expectedFunctionName(2048, 120, DEFAULT_EPHEMERAL_STORAGE_IN_MB),
);
- const fns = await getFunctions({
+ const fns = await mockImplementation.getFunctions({
region: 'us-east-1',
compatibleOnly: true,
});
@@ -159,11 +161,11 @@ test('Should be able to get the function afterwards', async () => {
markFunctionAsIncompatible(
expectedFunctionName(2048, 120, DEFAULT_EPHEMERAL_STORAGE_IN_MB),
);
- const compatibleFns = await getFunctions({
+ const compatibleFns = await mockImplementation.getFunctions({
region: 'us-east-1',
compatibleOnly: true,
});
- const incompatibleFns = await getFunctions({
+ const incompatibleFns = await mockImplementation.getFunctions({
region: 'us-east-1',
compatibleOnly: false,
});
diff --git a/packages/lambda/src/test/mock-implementation.ts b/packages/lambda/src/test/mock-implementation.ts
index d3408033be..b02466ad4a 100644
--- a/packages/lambda/src/test/mock-implementation.ts
+++ b/packages/lambda/src/test/mock-implementation.ts
@@ -6,6 +6,7 @@ import type {
} from '@remotion/serverless';
import {Readable} from 'stream';
import {estimatePrice} from '../api/estimate-price';
+import {deleteMockFunction, getAllMockFunctions} from '../api/mock-functions';
import {speculateFunctionName} from '../api/speculate-function-name';
import {MAX_EPHEMERAL_STORAGE_IN_MB} from '../defaults';
import type {AwsProvider} from '../functions/aws-implementation';
@@ -168,6 +169,8 @@ export const mockImplementation: ProviderSpecifics<AwsProvider> = {
};
},
isFlakyError,
+ deleteFunction: deleteMockFunction,
+ getFunctions: getAllMockFunctions,
};
export const mockServerImplementation: ServerProviderSpecifics = {
diff --git a/packages/serverless/src/provider-implementation.ts b/packages/serverless/src/provider-implementation.ts
index b5708f1183..1566213070 100644
--- a/packages/serverless/src/provider-implementation.ts
+++ b/packages/serverless/src/provider-implementation.ts
@@ -237,6 +237,33 @@ export type GetAccountId<Provider extends CloudProvider> = (options: {
region: Provider['region'];
}) => Promise<string>;
+export type DeleteFunctionInput<Provider extends CloudProvider> = {
+ region: Provider['region'];
+ functionName: string;
+};
+
+export type DeleteFunction<Provider extends CloudProvider> = (
+ options: DeleteFunctionInput<Provider>,
+) => Promise<void>;
+
+export type GetFunctionsInput<Provider extends CloudProvider> = {
+ region: Provider['region'];
+ compatibleOnly: boolean;
+ logLevel?: LogLevel;
+};
+
+export type FunctionInfo = {
+ functionName: string;
+ timeoutInSeconds: number;
+ memorySizeInMb: number;
+ version: string | null;
+ diskSizeInMb: number;
+};
+
+export type GetFunctions<Provider extends CloudProvider> = (
+ params: GetFunctionsInput<Provider>,
+) => Promise<FunctionInfo[]>;
+
export type ServerProviderSpecifics = {
getBrowserInstance: GetBrowserInstance;
forgetBrowserEventLoop: ForgetBrowserEventLoop;
@@ -278,4 +305,6 @@ export type ProviderSpecifics<Provider extends CloudProvider> = {
getMaxStillInlinePayloadSize: () => number;
getMaxNonInlinePayloadSizePerFunction: () => number;
getAccountId: GetAccountId<Provider>;
+ deleteFunction: DeleteFunction<Provider>;
+ getFunctions: GetFunctions<Provider>;
};