Skip to content

🎥 Make videos programmatically with React

`@remotion/lambda`: Fix how .zip location is specified

Jonny Burger922c9e03c881
diff --git a/packages/lambda/build.ts b/packages/lambda/build.ts
index 4f85cb01bc..09b46db5a7 100644
--- a/packages/lambda/build.ts
+++ b/packages/lambda/build.ts
@@ -2,7 +2,6 @@ import {BundlerInternals} from '@remotion/bundler';
import {dir} from '@remotion/compositor-linux-arm64-gnu';
import fs, {cpSync, readdirSync} from 'node:fs';
import path from 'node:path';
-import {FUNCTION_ZIP_ARM64} from './src/shared/function-zip-path';
import zl from 'zip-lib';
@@ -57,7 +56,7 @@ fs.cpSync(
`${outdir}/mappings.wasm`,
);
-await zl.archiveFolder(outdir, FUNCTION_ZIP_ARM64);
+await zl.archiveFolder(outdir, 'remotionlambda-arm64.zip');
fs.rmSync(outdir, {recursive: true});
console.log('Bundled Lambda');
diff --git a/packages/lambda/src/api/deploy-function.ts b/packages/lambda/src/api/deploy-function.ts
index 856f254651..2671720b54 100644
--- a/packages/lambda/src/api/deploy-function.ts
+++ b/packages/lambda/src/api/deploy-function.ts
@@ -14,7 +14,6 @@ import type {
} from '@remotion/serverless';
import {VERSION} from 'remotion/version';
import {awsFullClientSpecifics} from '../functions/full-client-implementation';
-import {FUNCTION_ZIP_ARM64} from '../shared/function-zip-path';
import {validateRuntimePreference} from '../shared/get-layers';
import {validateCustomRoleArn} from '../shared/validate-custom-role-arn';
import {validateCloudWatchRetentionPeriod} from '../shared/validate-retention-period';
@@ -87,7 +86,12 @@ export const internalDeployFunction = async <Provider extends CloudProvider>(
const created = await params.fullClientSpecifics.createFunction({
createCloudWatchLogGroup: params.createCloudWatchLogGroup,
region: params.region,
- zipFile: FUNCTION_ZIP_ARM64,
+ // Very delicate!
+ // this will output to
+ // - dist/esm/index.mjs
+ // - dist/api/deploy-function.js
+ // It only works because both are two levels deep
+ zipFile: '../../remotionlambda-arm64.zip',
functionName,
accountId,
memorySizeInMb: params.memorySizeInMb,
diff --git a/packages/lambda/src/shared/function-zip-path.ts b/packages/lambda/src/shared/function-zip-path.ts
deleted file mode 100644
index c597f21e91..0000000000
--- a/packages/lambda/src/shared/function-zip-path.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-// Don't concatenate as we don't want Bun bundler to hardcode this
-import path from 'node:path';
-
-const b = '../';
-const a = 'remotionlambda-arm64.zip';
-
-export const FUNCTION_ZIP_ARM64 = path.resolve(
- require.resolve(`../` + b),
- '..',
- '..',
- a,
-);
diff --git a/packages/lambda/src/test/integration/zip-path.test.ts b/packages/lambda/src/test/integration/zip-path.test.ts
new file mode 100644
index 0000000000..57e4a126e7
--- /dev/null
+++ b/packages/lambda/src/test/integration/zip-path.test.ts
@@ -0,0 +1,32 @@
+import {expect, test} from 'bun:test';
+import {readFile} from 'fs/promises';
+import path from 'path';
+
+// Just fixating this so we don't break this in the future
+test('CJS zip path must be two levels deep', async () => {
+ const dist = path.join(
+ __dirname,
+ '..',
+ '..',
+ '..',
+ 'dist',
+ 'api',
+ 'deploy-function.js',
+ );
+ const content = await readFile(dist, 'utf-8');
+ expect(content).toContain('../../remotionlambda-arm64.zip');
+});
+
+test('ESM zip path must be two levels deep', async () => {
+ const dist = path.join(
+ __dirname,
+ '..',
+ '..',
+ '..',
+ 'dist',
+ 'esm',
+ 'index.mjs',
+ );
+ const content = await readFile(dist, 'utf-8');
+ expect(content).toContain('../../remotionlambda-arm64.zip');
+});