Skip to content

🎥 Make videos programmatically with React

prebuild lambda function

Jonny Burger795406f93aa5
diff --git a/packages/lambda/.gitignore b/packages/lambda/.gitignore
index d0695a9fb8..ecd859df58 100644
--- a/packages/lambda/.gitignore
+++ b/packages/lambda/.gitignore
@@ -1,10 +1,2 @@
-build-render
-build-stitcher
node_modules
-function.zip
-function-render.zip
-function-stitcher.zip
ffmpeg
-chromium.zip
-chromium
-src/admin/remotion.zip
diff --git a/packages/lambda/package.json b/packages/lambda/package.json
index 1b4b075b00..132cf87767 100644
--- a/packages/lambda/package.json
+++ b/packages/lambda/package.json
@@ -12,6 +12,7 @@
"test": "eslint src --ext ts,tsx && tsc && jest",
"watch": "tsc -w",
"build": "tsc -d",
+ "buildlambda": "ts-node src/admin/bundle-lambda.ts",
"start": "ts-node src/run.ts"
},
"author": "",
@@ -29,14 +30,10 @@
"@remotion/renderer": "^2.1.4",
"aws-policies": "^1.0.1",
"dotenv": "^10.0.0",
- "esbuild": "^0.11.12",
"minimist": "^1.2.5",
"p-limit": "^3.1.0",
- "p-retry": "^4.6.0",
"prompt": "^1.1.0",
- "remotion": "^2.1.4",
- "ts-node": "^9.1.1",
- "zip-lib": "^0.7.2"
+ "remotion": "^2.1.4"
},
"peerDependencies": {
"react": "^17.0.1",
@@ -47,11 +44,14 @@
"@types/node": "^14.14.14",
"@types/prompt": "^1.1.0",
"@types/jest": "^26.0.23",
+ "esbuild": "^0.11.12",
+ "zip-lib": "^0.7.2",
"eslint": "^7.4.0",
"jest": "^26.6.3",
"prettier": "^2.0.5",
"prettier-plugin-organize-imports": "^1.1.1",
"ts-jest": "^26.5.6",
+ "ts-node": "^9.1.1",
"typescript": "^4.1.2"
},
"publishConfig": {
diff --git a/packages/lambda/remotionlambda.zip b/packages/lambda/remotionlambda.zip
new file mode 100644
index 0000000000..b235843262
Binary files /dev/null and b/packages/lambda/remotionlambda.zip differ
diff --git a/packages/lambda/src/api/bundle-lambda.ts b/packages/lambda/src/admin/bundle-lambda.ts
similarity index 67%
rename from packages/lambda/src/api/bundle-lambda.ts
rename to packages/lambda/src/admin/bundle-lambda.ts
index 7c4267c9fa..328941b68d 100644
--- a/packages/lambda/src/api/bundle-lambda.ts
+++ b/packages/lambda/src/admin/bundle-lambda.ts
@@ -1,10 +1,10 @@
import fs from 'fs';
import path from 'path';
-import {tmpDir} from '../shared/tmpdir';
+import {FUNCTION_ZIP} from '../defaults';
import esbuild = require('esbuild');
import zl = require('zip-lib');
-export const bundleLambda = async () => {
+const bundleLambda = async () => {
const outdir = path.join(__dirname, '..', `build-render`);
fs.mkdirSync(outdir, {
recursive: true,
@@ -25,7 +25,15 @@ export const bundleLambda = async () => {
entryPoints: [template],
});
- const out = path.join(tmpDir('remotion-fn'), `function-render.zip`);
- await zl.archiveFolder(outdir, out);
- return out;
+ await zl.archiveFolder(outdir, FUNCTION_ZIP);
+ await fs.promises.rm(outfile);
};
+
+bundleLambda()
+ .then(() => {
+ console.log('Lambda bundled');
+ })
+ .catch((err) => {
+ console.log(err);
+ process.exit(1);
+ });
diff --git a/packages/lambda/src/api/__mocks__/bundle-lambda.ts b/packages/lambda/src/api/__mocks__/bundle-lambda.ts
deleted file mode 100644
index 5b1a2ba22b..0000000000
--- a/packages/lambda/src/api/__mocks__/bundle-lambda.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-import {bundleLambda as original} from '../bundle-lambda';
-
-export const bundleLambda: typeof original = async () => {
- return Promise.resolve('/path/to/functionbundle');
-};
diff --git a/packages/lambda/src/api/deploy-function.ts b/packages/lambda/src/api/deploy-function.ts
index f6606cbebf..36e70458c3 100644
--- a/packages/lambda/src/api/deploy-function.ts
+++ b/packages/lambda/src/api/deploy-function.ts
@@ -1,11 +1,10 @@
import {AwsRegion} from '../pricing/aws-regions';
-import {RENDER_FN_PREFIX} from '../shared/constants';
+import {FUNCTION_ZIP, RENDER_FN_PREFIX} from '../shared/constants';
import {getAccountId} from '../shared/get-account-id';
import {randomHash} from '../shared/random-hash';
import {validateAwsRegion} from '../shared/validate-aws-region';
import {validateMemorySize} from '../shared/validate-memory-size';
import {validateTimeout} from '../shared/validate-timeout';
-import {bundleLambda} from './bundle-lambda';
import {createFunction} from './create-function';
/**
@@ -26,14 +25,11 @@ export const deployFunction = async (options: {
validateAwsRegion(options.region);
const fnNameRender = RENDER_FN_PREFIX + randomHash();
- const [renderOut, accountId] = await Promise.all([
- bundleLambda(),
- getAccountId({region: options.region}),
- ]);
+ const accountId = await getAccountId({region: options.region});
const created = await createFunction({
region: options.region,
- zipFile: renderOut,
+ zipFile: FUNCTION_ZIP,
functionName: fnNameRender,
accountId,
memorySizeInMb: options.memorySizeInMb,
diff --git a/packages/lambda/src/shared/constants.ts b/packages/lambda/src/shared/constants.ts
index 804b36f7a2..7cf1063826 100644
--- a/packages/lambda/src/shared/constants.ts
+++ b/packages/lambda/src/shared/constants.ts
@@ -1,3 +1,4 @@
+import path from 'path';
import {
Codec,
ImageFormat,
@@ -281,3 +282,8 @@ export type RenderProgress = {
};
export type LambdaAcl = 'public-read' | 'private';
+
+export const FUNCTION_ZIP = path.join(
+ path.resolve(__dirname, '..', '..'),
+ `remotionlambda.zip`
+);
diff --git a/packages/lambda/src/test/integration/deploy-function.test.ts b/packages/lambda/src/test/integration/deploy-function.test.ts
index 2a9bc80336..2479388366 100644
--- a/packages/lambda/src/test/integration/deploy-function.test.ts
+++ b/packages/lambda/src/test/integration/deploy-function.test.ts
@@ -18,7 +18,6 @@ jest.mock('../../api/bucket-exists');
jest.mock('../../api/clean-items');
jest.mock('../../api/create-function');
jest.mock('../../api/delete-function');
-jest.mock('../../api/bundle-lambda');
jest.mock('../../api/get-functions');
jest.mock('../../shared/get-account-id');