Skip to content

🎥 Make videos programmatically with React

fix

Jonny Burger0cc20d2b4bb1
diff --git a/packages/lambda/src/functions/index.ts b/packages/lambda/src/functions/index.ts
index ffe21ef11b..8687c93a5c 100644
--- a/packages/lambda/src/functions/index.ts
+++ b/packages/lambda/src/functions/index.ts
@@ -14,7 +14,6 @@ import {rendererHandler} from './renderer';
import {startHandler} from './start';
import {stillHandler} from './still';
import {randomHash} from '../shared/random-hash';
-import {Log} from '../cli/log';
export const handler = streamifyResponse(
async (
@@ -54,14 +53,15 @@ export const handler = streamifyResponse(
responseStream.write(JSON.stringify(response));
responseStream.end();
} catch (err) {
- Log.error(err);
- responseStream.write(
- JSON.stringify({
- type: 'error',
- message: (err as Error).message,
- stack: (err as Error).stack,
- })
- );
+ RenderInternals.Log.error(err);
+
+ const response = {
+ type: 'error',
+ message: (err as Error).message,
+ stack: (err as Error).stack,
+ };
+
+ responseStream.write(JSON.stringify(response));
responseStream.end();
}
diff --git a/packages/lambda/src/functions/launch.ts b/packages/lambda/src/functions/launch.ts
index fe108e1808..c71c6077f4 100644
--- a/packages/lambda/src/functions/launch.ts
+++ b/packages/lambda/src/functions/launch.ts
@@ -1,12 +1,14 @@
-import {InvokeCommand} from '@aws-sdk/client-lambda';
import {RenderInternals} from '@remotion/renderer';
import fs, {existsSync, mkdirSync, rmSync} from 'node:fs';
import {join} from 'node:path';
import {Internals} from 'remotion';
import {VERSION} from 'remotion/version';
-import {getLambdaClient} from '../shared/aws-clients';
import {cleanupSerializedInputProps} from '../shared/cleanup-serialized-input-props';
-import type {LambdaPayload, RenderMetadata} from '../shared/constants';
+import type {
+ LambdaPayload,
+ LambdaPayloads,
+ RenderMetadata,
+} from '../shared/constants';
import {
CONCAT_FOLDER_TOKEN,
encodingProgressKey,
@@ -50,6 +52,7 @@ import {
compressInputProps,
serializeOrThrow,
} from '../shared/compress-props';
+import {callLambda} from '../shared/call-lambda';
type Options = {
expectedBucketOwner: string;
@@ -61,20 +64,17 @@ const callFunctionWithRetry = async ({
retries,
functionName,
}: {
- payload: unknown;
+ payload: LambdaPayloads[LambdaRoutines.renderer];
retries: number;
functionName: string;
}): Promise<unknown> => {
try {
- await getLambdaClient(getCurrentRegionInFunction()).send(
- new InvokeCommand({
- FunctionName: functionName,
- // @ts-expect-error
- Payload: JSON.stringify(payload),
- InvocationType: 'Event',
- }),
- {}
- );
+ await callLambda({
+ functionName,
+ payload,
+ region: getCurrentRegionInFunction(),
+ type: LambdaRoutines.renderer,
+ });
} catch (err) {
if ((err as Error).name === 'ResourceConflictException') {
if (retries > 10) {
diff --git a/packages/lambda/src/functions/renderer.ts b/packages/lambda/src/functions/renderer.ts
index 52466e8408..ff196fa815 100644
--- a/packages/lambda/src/functions/renderer.ts
+++ b/packages/lambda/src/functions/renderer.ts
@@ -1,10 +1,8 @@
-import {InvokeCommand} from '@aws-sdk/client-lambda';
import type {BrowserLog, Codec} from '@remotion/renderer';
import {RenderInternals} from '@remotion/renderer';
import fs from 'node:fs';
import path from 'node:path';
import {VERSION} from 'remotion/version';
-import {getLambdaClient} from '../shared/aws-clients';
import {writeLambdaInitializedFile} from '../shared/chunk-progress';
import type {LambdaPayload, LambdaPayloads} from '../shared/constants';
import {
@@ -26,6 +24,7 @@ import {
writeLambdaError,
} from './helpers/write-lambda-error';
import {decompressInputProps} from '../shared/compress-props';
+import {callLambda} from '../shared/call-lambda';
type Options = {
expectedBucketOwner: string;
@@ -340,14 +339,12 @@ export const rendererHandler = async (
retriesLeft: params.retriesLeft - 1,
attempt: params.attempt + 1,
};
- await getLambdaClient(getCurrentRegionInFunction()).send(
- new InvokeCommand({
- FunctionName: process.env.AWS_LAMBDA_FUNCTION_NAME,
- // @ts-expect-error
- Payload: JSON.stringify(retryPayload),
- InvocationType: 'Event',
- })
- );
+ await callLambda({
+ functionName: process.env.AWS_LAMBDA_FUNCTION_NAME as string,
+ payload: retryPayload,
+ type: LambdaRoutines.renderer,
+ region: getCurrentRegionInFunction(),
+ });
}
}
};
diff --git a/packages/lambda/src/functions/start.ts b/packages/lambda/src/functions/start.ts
index 82212e0216..c3bec6c253 100644
--- a/packages/lambda/src/functions/start.ts
+++ b/packages/lambda/src/functions/start.ts
@@ -1,13 +1,12 @@
-import {InvokeCommand} from '@aws-sdk/client-lambda';
import {VERSION} from 'remotion/version';
import {getOrCreateBucket} from '../api/get-or-create-bucket';
-import {getLambdaClient} from '../shared/aws-clients';
import type {LambdaPayload} from '../shared/constants';
import {initalizedMetadataKey, LambdaRoutines} from '../shared/constants';
import {convertToServeUrl} from '../shared/convert-to-serve-url';
import {randomHash} from '../shared/random-hash';
import {getCurrentRegionInFunction} from './helpers/get-current-region';
import {lambdaWriteFile} from './helpers/io';
+import {callLambda} from '../shared/call-lambda';
type Options = {
expectedBucketOwner: string;
@@ -95,15 +94,14 @@ export const startHandler = async (params: LambdaPayload, options: Options) => {
audioCodec: params.audioCodec,
};
- await getLambdaClient(getCurrentRegionInFunction()).send(
- new InvokeCommand({
- FunctionName: process.env.AWS_LAMBDA_FUNCTION_NAME,
- // @ts-expect-error
- Payload: JSON.stringify(payload),
- InvocationType: 'Event',
- })
- );
+ await callLambda({
+ payload,
+ functionName: process.env.AWS_LAMBDA_FUNCTION_NAME as string,
+ region: getCurrentRegionInFunction(),
+ type: LambdaRoutines.launch,
+ });
await initialFile;
+
return {
bucketName,
renderId,