Skip to content

🎥 Make videos programmatically with React

move start handler to `@remotion/serverless`

Jonny Burger66210d66d20c
diff --git a/packages/lambda/src/functions/aws-implementation.ts b/packages/lambda/src/functions/aws-implementation.ts
index 6f29dc5055..a4a1b04316 100644
--- a/packages/lambda/src/functions/aws-implementation.ts
+++ b/packages/lambda/src/functions/aws-implementation.ts
@@ -96,4 +96,12 @@ export const awsImplementation: ProviderSpecifics<AwsProvider> = {
callFunctionAsync: callFunctionAsyncImplementation,
callFunctionStreaming: callFunctionWithStreamingImplementation,
callFunctionSync: callFunctionSyncImplementation,
+ getCurrentFunctionName() {
+ const name = process.env.AWS_LAMBDA_FUNCTION_NAME;
+ if (!name) {
+ throw new Error('Expected AWS_LAMBDA_FUNCTION_NAME to be set');
+ }
+
+ return name;
+ },
};
diff --git a/packages/lambda/src/functions/index.ts b/packages/lambda/src/functions/index.ts
index ef7f78d73e..da94531865 100644
--- a/packages/lambda/src/functions/index.ts
+++ b/packages/lambda/src/functions/index.ts
@@ -10,6 +10,7 @@ import type {
import {
compositionsHandler,
infoHandler,
+ startHandler,
streamWriter,
} from '@remotion/serverless';
import type {ServerlessPayload} from '@remotion/serverless/client';
@@ -30,7 +31,6 @@ import {streamifyResponse} from './helpers/streamify-response';
import {launchHandler} from './launch';
import {progressHandler} from './progress';
import {rendererHandler} from './renderer';
-import {startHandler} from './start';
import {stillHandler} from './still';
const innerHandler = async <Provider extends CloudProvider>({
diff --git a/packages/lambda/src/test/mock-implementation.ts b/packages/lambda/src/test/mock-implementation.ts
index c578518233..425db25e69 100644
--- a/packages/lambda/src/test/mock-implementation.ts
+++ b/packages/lambda/src/test/mock-implementation.ts
@@ -1,5 +1,6 @@
import type {ProviderSpecifics} from '@remotion/serverless';
import {Readable} from 'stream';
+import {speculateFunctionName} from '../client';
import type {AwsProvider} from '../functions/aws-implementation';
import {convertToServeUrlImplementation} from '../shared/convert-to-serve-url';
import {
@@ -128,4 +129,10 @@ export const mockImplementation: ProviderSpecifics<AwsProvider> = {
callFunctionAsync: getMockCallFunctionAsync,
callFunctionStreaming: getMockCallFunctionStreaming,
callFunctionSync: getMockCallFunctionSync,
+ getCurrentFunctionName: () =>
+ speculateFunctionName({
+ diskSizeInMb: 10240,
+ memorySizeInMb: 3009,
+ timeoutInSeconds: 120,
+ }),
};
diff --git a/packages/serverless/src/compositions.ts b/packages/serverless/src/handlers/compositions.ts
similarity index 90%
rename from packages/serverless/src/compositions.ts
rename to packages/serverless/src/handlers/compositions.ts
index f5ea4a1286..1e75dee82b 100644
--- a/packages/serverless/src/compositions.ts
+++ b/packages/serverless/src/handlers/compositions.ts
@@ -1,15 +1,15 @@
import {RenderInternals} from '@remotion/renderer';
import {VERSION} from 'remotion/version';
-import {decompressInputProps} from './compress-props';
-import type {ServerlessPayload} from './constants';
-import {ServerlessRoutines} from './constants';
+import {decompressInputProps} from '../compress-props';
+import type {ServerlessPayload} from '../constants';
+import {ServerlessRoutines} from '../constants';
import {
forgetBrowserEventLoop,
getBrowserInstance,
-} from './get-browser-instance';
-import {internalGetOrCreateBucket} from './get-or-create-bucket';
-import type {ProviderSpecifics} from './provider-implementation';
-import type {CloudProvider} from './types';
+} from '../get-browser-instance';
+import {internalGetOrCreateBucket} from '../get-or-create-bucket';
+import type {ProviderSpecifics} from '../provider-implementation';
+import type {CloudProvider} from '../types';
type Options = {
expectedBucketOwner: string;
diff --git a/packages/lambda/src/functions/start.ts b/packages/serverless/src/handlers/start.ts
similarity index 90%
rename from packages/lambda/src/functions/start.ts
rename to packages/serverless/src/handlers/start.ts
index 053e72ac6c..7fc3726f33 100644
--- a/packages/lambda/src/functions/start.ts
+++ b/packages/serverless/src/handlers/start.ts
@@ -1,16 +1,10 @@
-import {
- makeInitialOverallRenderProgress,
- type CloudProvider,
- type ProviderSpecifics,
-} from '@remotion/serverless';
-import type {ServerlessPayload} from '@remotion/serverless/client';
-import {
- ServerlessRoutines,
- internalGetOrCreateBucket,
- overallProgressKey,
-} from '@remotion/serverless/client';
import {VERSION} from 'remotion/version';
-import type {AwsRegion} from '../regions';
+import type {ServerlessPayload} from '../constants';
+import {ServerlessRoutines, overallProgressKey} from '../constants';
+import {internalGetOrCreateBucket} from '../get-or-create-bucket';
+import {makeInitialOverallRenderProgress} from '../overall-render-progress';
+import type {ProviderSpecifics} from '../provider-implementation';
+import type {CloudProvider} from '../types';
type Options = {
expectedBucketOwner: string;
@@ -124,10 +118,10 @@ export const startHandler = async <Provider extends CloudProvider>(
};
await providerSpecifics.callFunctionAsync({
- functionName: process.env.AWS_LAMBDA_FUNCTION_NAME as string,
+ functionName: providerSpecifics.getCurrentFunctionName(),
type: ServerlessRoutines.launch,
payload,
- region: region as AwsRegion,
+ region,
timeoutInTest: options.timeoutInMilliseconds,
});
diff --git a/packages/serverless/src/index.ts b/packages/serverless/src/index.ts
index e15bbbc122..29023c4dd3 100644
--- a/packages/serverless/src/index.ts
+++ b/packages/serverless/src/index.ts
@@ -1,4 +1,5 @@
-export {compositionsHandler} from './compositions';
+export {compositionsHandler} from './handlers/compositions';
+export {startHandler} from './handlers/start';
export {PostRenderData, ServerlessRoutines} from './constants';
export {getCredentialsFromOutName} from './expected-out-name';
diff --git a/packages/serverless/src/provider-implementation.ts b/packages/serverless/src/provider-implementation.ts
index 735451fafd..9b5f0ea315 100644
--- a/packages/serverless/src/provider-implementation.ts
+++ b/packages/serverless/src/provider-implementation.ts
@@ -179,4 +179,5 @@ export type ProviderSpecifics<Provider extends CloudProvider> = {
callFunctionAsync: CallFunctionAsync<Provider>;
callFunctionStreaming: CallFunctionStreaming<Provider>;
callFunctionSync: CallFunctionSync<Provider>;
+ getCurrentFunctionName: () => string;
};