🎥 Make videos programmatically with React
`@remotion/lambda`: fix lambda invokation crashing when input props and resolved props don't separately but in cumulation exceed lambda payload limit
Jonny Burger8e65d7e04d5d
diff --git a/packages/example/testlambda.mjs b/packages/example/testlambda.mjsindex 9aa1ff3801..ba7f19cb89 100644--- a/packages/example/testlambda.mjs+++ b/packages/example/testlambda.mjs@@ -7,7 +7,6 @@ execSync('pnpm run buildlambda', {execSync('pnpm exec remotion lambda functions rmall -f', {stdio: 'inherit',});-execSync('pnpm exec remotion lambda sites create --site-name=testbed-v6 --log=verbose',{@@ -18,14 +17,12 @@ execSync(execSync('pnpm exec remotion lambda functions deploy --memory=3000', {stdio: 'inherit',});-execSync('pnpm exec remotion lambda render testbed-v6 react-svg --log=verbose',{stdio: 'inherit',});-execSync('pnpm exec remotion lambda still testbed-v6 huge-payload --log=verbose',{@@ -33,13 +30,13 @@ execSync(});execSync(- `pnpm exec remotion lambda still testbed-v6 140kb-payload --props="${JSON.stringify(+ `pnpm exec remotion lambda still testbed-v6 140kb-payload --props='${JSON.stringify({str: 'a'.repeat(140 * 1000),date: 'remotion-date:' + new Date('2020-01-01').toISOString(),file: 'nested/mp4.png',}- )}" --log=verbose`,+ )}' --log=verbose`,{stdio: 'inherit',}diff --git a/packages/lambda/src/api/get-compositions-on-lambda.ts b/packages/lambda/src/api/get-compositions-on-lambda.tsindex 16d5c83e3d..3111df579f 100644--- a/packages/lambda/src/api/get-compositions-on-lambda.ts+++ b/packages/lambda/src/api/get-compositions-on-lambda.ts@@ -60,7 +60,9 @@ export const getCompositionsOnLambda = async ({region,userSpecifiedBucketName: bucketName ?? null,propsType: 'input-props',- needsToUpload: getNeedsToUpload('video-or-audio', stringifiedInputProps),+ needsToUpload: getNeedsToUpload('video-or-audio', [+ stringifiedInputProps.length,+ ]),});try {diff --git a/packages/lambda/src/api/make-lambda-payload.ts b/packages/lambda/src/api/make-lambda-payload.tsindex 16a32b88ae..0ee0e546e2 100644--- a/packages/lambda/src/api/make-lambda-payload.ts+++ b/packages/lambda/src/api/make-lambda-payload.ts@@ -73,7 +73,9 @@ export const makeLambdaRenderMediaPayload = async ({const serialized = await compressInputProps({stringifiedInputProps,region,- needsToUpload: getNeedsToUpload('video-or-audio', stringifiedInputProps),+ needsToUpload: getNeedsToUpload('video-or-audio', [+ stringifiedInputProps.length,+ ]),userSpecifiedBucketName: bucketName ?? null,propsType: 'input-props',});diff --git a/packages/lambda/src/api/render-still-on-lambda.ts b/packages/lambda/src/api/render-still-on-lambda.tsindex da364670ec..f339ef30e9 100644--- a/packages/lambda/src/api/render-still-on-lambda.ts+++ b/packages/lambda/src/api/render-still-on-lambda.ts@@ -110,7 +110,7 @@ export const renderStillOnLambda = async ({const serializedInputProps = await compressInputProps({stringifiedInputProps,region,- needsToUpload: getNeedsToUpload('still', stringifiedInputProps),+ needsToUpload: getNeedsToUpload('still', [stringifiedInputProps.length]),userSpecifiedBucketName: forceBucketName ?? null,propsType: 'input-props',});diff --git a/packages/lambda/src/functions/launch.ts b/packages/lambda/src/functions/launch.tsindex e488b83bb4..9853561340 100644--- a/packages/lambda/src/functions/launch.ts+++ b/packages/lambda/src/functions/launch.ts@@ -259,10 +259,12 @@ const innerLaunchHandler = async (params: LambdaPayload, options: Options) => {const serializedResolved = serializeOrThrow(comp.props, 'resolved-props');- const needsToUpload = getNeedsToUpload(- 'video-or-audio',- serializedResolved + params.inputProps- );+ const needsToUpload = getNeedsToUpload('video-or-audio', [+ serializedResolved.length,+ params.inputProps.type === 'bucket-url'+ ? params.inputProps.hash.length+ : params.inputProps.payload.length,+ ]);const serializedResolvedProps = await compressInputProps({propsType: 'resolved-props',diff --git a/packages/lambda/src/shared/compress-props.ts b/packages/lambda/src/shared/compress-props.tsindex 7c8b82a301..6b08943113 100644--- a/packages/lambda/src/shared/compress-props.ts+++ b/packages/lambda/src/shared/compress-props.ts@@ -29,15 +29,20 @@ export const serializeOrThrow = (export const getNeedsToUpload = (type: 'still' | 'video-or-audio',- stringifiedInputProps: string+ sizes: number[]) => {- const MAX_INLINE_PAYLOAD_SIZE = type === 'still' ? 5000000 : 200000;- if (stringifiedInputProps.length > MAX_INLINE_PAYLOAD_SIZE) {+ const MARGIN = 5_000;+ const MAX_INLINE_PAYLOAD_SIZE =+ (type === 'still' ? 5_000_000 : 200_000) - MARGIN;++ const sizesAlreadyUsed = sizes.reduce((a, b) => a + b);++ if (sizesAlreadyUsed > MAX_INLINE_PAYLOAD_SIZE) {console.warn(`Warning: The props are over ${Math.round(MAX_INLINE_PAYLOAD_SIZE / 1000)}KB (${Math.ceil(- stringifiedInputProps.length / 1024+ sizesAlreadyUsed / 1024)}KB) in size. Uploading them to S3 to circumvent AWS Lambda payload size, which may lead to slowdown.`);return true;