Skip to content

🎥 Make videos programmatically with React

upload function directly

Jonny Burger4d0652bad4e0
diff --git a/packages/lambda/src/cli/deploy.ts b/packages/lambda/src/cli/deploy.ts
new file mode 100644
index 0000000000..39bcf8833a
--- /dev/null
+++ b/packages/lambda/src/cli/deploy.ts
@@ -0,0 +1,7 @@
+import {createLambda} from '../create-lambda';
+
+export const DEPLOY_COMMAND = 'deploy';
+
+export const deployCommand = async () => {
+ await createLambda();
+};
diff --git a/packages/lambda/src/cli/index.ts b/packages/lambda/src/cli/index.ts
index 2a30cbd9ba..033fa1a321 100644
--- a/packages/lambda/src/cli/index.ts
+++ b/packages/lambda/src/cli/index.ts
@@ -1,5 +1,6 @@
import {parsedCli} from './args';
import {cleanupCommand, CLEANUP_COMMAND} from './cleanup';
+import {deployCommand, DEPLOY_COMMAND} from './deploy';
import {printHelp} from './help';
import {Log} from './log';
import {renderCommand, RENDER_COMMAND} from './render';
@@ -11,6 +12,10 @@ export const cli = async () => {
process.exit(0);
}
+ if (parsedCli._[0] === DEPLOY_COMMAND) {
+ return deployCommand();
+ }
+
if (parsedCli._[0] === UPLOAD_COMMAND) {
return uploadCommand();
}
diff --git a/packages/lambda/src/create-lambda.ts b/packages/lambda/src/create-lambda.ts
index 94c2a78433..eb1d8820ab 100644
--- a/packages/lambda/src/create-lambda.ts
+++ b/packages/lambda/src/create-lambda.ts
@@ -1,18 +1,13 @@
import {CreateFunctionCommand, LambdaClient} from '@aws-sdk/client-lambda';
-import {PutObjectCommand, S3Client} from '@aws-sdk/client-s3';
-import {CliInternals} from '@remotion/cli';
-import {createReadStream} from 'fs';
-import path from 'path';
+import {readFileSync} from 'fs';
import {bundleLambda} from './bundle-lambda';
import {
EFS_MOUNT_PATH,
ENABLE_EFS,
MEMORY_SIZE,
REGION,
- REMOTION_RENDER_FN_ZIP,
RENDER_FN_PREFIX,
} from './constants';
-import {deploySite} from './deploy-site';
import {ensureLayers} from './lambda-layers';
import {waitForLambdaReady} from './wait-for-lambda-ready';
@@ -20,46 +15,21 @@ const lambdaClient = new LambdaClient({
region: REGION,
});
-const s3Client = new S3Client({region: REGION});
-
type Developer = 'jonny' | 'shankhadeep';
const developer: Developer = 'jonny' as Developer;
-export const createLambda = CliInternals.xns(async () => {
+export const createLambda = async () => {
const {layerArn} = await ensureLayers(lambdaClient);
console.log('Done creating layers');
- const id = String(Math.random());
- const s3KeyRender = `${REMOTION_RENDER_FN_ZIP}${id}.zip`;
const fnNameRender =
RENDER_FN_PREFIX + String(Math.random()).replace('0.', '');
const renderOut = await bundleLambda('render');
console.log('done Bundling');
- const {url, bucketName} = await deploySite(
- path.join(__dirname, '..', 'remotion-project', 'index.ts'),
- {
- // TODO: Start uploading lambda now
- onBucketCreated: async () => {},
- }
- );
- console.log(url);
- await s3Client.send(
- new PutObjectCommand({
- Bucket: bucketName,
- Body: createReadStream(renderOut),
- Key: s3KeyRender,
- ACL: 'public-read',
- })
- );
- // TODO: Potentially big, should show progress bar
-
- console.log('lambdas uploaded');
-
const created = await lambdaClient.send(
new CreateFunctionCommand({
Code: {
- S3Bucket: bucketName,
- S3Key: s3KeyRender,
+ ZipFile: readFileSync(renderOut),
},
FunctionName: fnNameRender,
Handler: 'index.handler',
@@ -67,7 +37,7 @@ export const createLambda = CliInternals.xns(async () => {
developer === 'shankhadeep'
? 'arn:aws:iam::363307378317:role/awesomeLambda'
: 'arn:aws:iam::976210361945:role/lambda-admin', // IAM_ROLE_ARN; e.g., arn:aws:iam::650138640062:role/v3-lambda-tutorial-lambda-role
- Runtime: 'nodejs12.x',
+ Runtime: 'nodejs14.x',
Description: 'Renders a Remotion video.',
MemorySize: MEMORY_SIZE,
Timeout: 120,
@@ -109,7 +79,5 @@ export const createLambda = CliInternals.xns(async () => {
await waitForLambdaReady(created.FunctionName);
return {
functionName: created.FunctionName,
- bucketName,
- bucketUrl: url,
};
-});
+};
diff --git a/packages/lambda/src/deploy-site.ts b/packages/lambda/src/deploy-site.ts
index 6bde43a5e9..dc7226f7f3 100644
--- a/packages/lambda/src/deploy-site.ts
+++ b/packages/lambda/src/deploy-site.ts
@@ -57,6 +57,5 @@ export const deploySite = async (
return {
url: makeS3Url(bucketName),
- bucketName,
};
};
diff --git a/packages/lambda/src/run.ts b/packages/lambda/src/run.ts
index 010e300a5b..011ccc2545 100644
--- a/packages/lambda/src/run.ts
+++ b/packages/lambda/src/run.ts
@@ -1,4 +1,5 @@
import {CliInternals} from '@remotion/cli';
+import path from 'path';
import {lambdaClient, s3Client} from './aws-clients';
import {callLambda} from './call-lambda';
import {checkLambdaStatus} from './check-lambda-status';
@@ -6,10 +7,11 @@ import {cleanupLambdas, getRemotionLambdas} from './cleanup/cleanup-lambdas';
import {cleanUpBuckets, getRemotionS3Buckets} from './cleanup/s3-buckets';
import {LambdaRoutines} from './constants';
import {createLambda} from './create-lambda';
+import {deploySite} from './deploy-site';
import {makeS3Url} from './make-s3-url';
import {sleep} from './sleep';
-const DEPLOY = false;
+const DEPLOY = true;
const getFnName = async (): Promise<{
functionName: string;
@@ -18,8 +20,18 @@ const getFnName = async (): Promise<{
if (DEPLOY) {
await cleanupLambdas({lambdaClient});
await cleanUpBuckets({s3client: s3Client});
- const {functionName, bucketUrl} = await createLambda();
- return {functionName, bucketUrl};
+
+ const {functionName} = await createLambda();
+
+ const {url} = await deploySite(
+ path.join(__dirname, '..', 'remotion-project', 'index.ts'),
+ {
+ // TODO: Start uploading lambda now
+ onBucketCreated: async () => {},
+ }
+ );
+
+ return {functionName, bucketUrl: url};
}
const lambdas = await getRemotionLambdas(lambdaClient);