Skip to content

🎥 Make videos programmatically with React

can opt out of bucket creation, rename deploy to upload

Jonny Burger478261403718
diff --git a/packages/lambda/src/cli/deploy.ts b/packages/lambda/src/cli/deploy.ts
index 85049f7d72..a5325a86ad 100644
--- a/packages/lambda/src/cli/deploy.ts
+++ b/packages/lambda/src/cli/deploy.ts
@@ -14,7 +14,9 @@ import {
import {parsedCli} from './args';
import {Log} from './log';
-export const deployCommand = async () => {
+export const UPLOAD_COMMAND = 'upload';
+
+export const uploadCommand = async () => {
const fileName = parsedCli._[1];
if (!fileName) {
Log.error('No entry file passed.');
diff --git a/packages/lambda/src/cli/help.ts b/packages/lambda/src/cli/help.ts
index f8130e6ccf..0789726213 100644
--- a/packages/lambda/src/cli/help.ts
+++ b/packages/lambda/src/cli/help.ts
@@ -1,6 +1,9 @@
import chalk from 'chalk';
import {BINARY_NAME} from '../bundle-remotion';
+import {CLEANUP_COMMAND} from './cleanup';
+import {UPLOAD_COMMAND} from './deploy';
import {Log} from './log';
+import {RENDER_COMMAND} from './render';
const packagejson = require('../../package.json');
@@ -13,15 +16,15 @@ export const printHelp = () => {
Log.info();
Log.info('Available commands:');
Log.info('');
- Log.info(`${BINARY_NAME} deploy <index-file.ts>`);
- Log.info(chalk.gray('Deploy a lambda.'));
+ Log.info(`${BINARY_NAME} ${UPLOAD_COMMAND} <index-file.ts>`);
+ Log.info(chalk.gray('Upload a Remotion project to S3.'));
Log.info();
- Log.info(`${BINARY_NAME} render <index-file.ts>`);
+ Log.info(`${BINARY_NAME} ${RENDER_COMMAND} <s3-url>`);
Log.info(chalk.gray('Render a video on the cloud.'));
Log.info();
- Log.info(`${BINARY_NAME} cleanup`);
+ Log.info(`${BINARY_NAME} ${CLEANUP_COMMAND}`);
Log.info(
chalk.gray('Delete Remotion-related infrastructure from your AWS account.')
);
diff --git a/packages/lambda/src/cli/index.ts b/packages/lambda/src/cli/index.ts
index cbbfcecea0..6f4cc8a862 100644
--- a/packages/lambda/src/cli/index.ts
+++ b/packages/lambda/src/cli/index.ts
@@ -1,9 +1,9 @@
import {parsedCli} from './args';
import {cleanupCommand, CLEANUP_COMMAND} from './cleanup';
-import {deployCommand} from './deploy';
+import {uploadCommand, UPLOAD_COMMAND} from './deploy';
import {printHelp} from './help';
import {Log} from './log';
-import {renderCommand} from './render';
+import {renderCommand, RENDER_COMMAND} from './render';
export const cli = async () => {
if (parsedCli.help || parsedCli._.length === 0) {
@@ -11,11 +11,11 @@ export const cli = async () => {
process.exit(0);
}
- if (parsedCli._[0] === 'deploy') {
- return deployCommand();
+ if (parsedCli._[0] === UPLOAD_COMMAND) {
+ return uploadCommand();
}
- if (parsedCli._[0] === 'render') {
+ if (parsedCli._[0] === RENDER_COMMAND) {
return renderCommand();
}
diff --git a/packages/lambda/src/cli/render.ts b/packages/lambda/src/cli/render.ts
index 24eee9f74a..e07fdf78cf 100644
--- a/packages/lambda/src/cli/render.ts
+++ b/packages/lambda/src/cli/render.ts
@@ -8,6 +8,8 @@ import {sleep} from '../sleep';
import {parsedCli} from './args';
import {Log} from './log';
+export const RENDER_COMMAND = 'render';
+
export const renderCommand = async () => {
const serveUrl = parsedCli._[1];
if (!serveUrl) {
diff --git a/packages/lambda/src/deploy-site.ts b/packages/lambda/src/deploy-site.ts
index 4fe558ecae..6bde43a5e9 100644
--- a/packages/lambda/src/deploy-site.ts
+++ b/packages/lambda/src/deploy-site.ts
@@ -1,7 +1,8 @@
import {CreateBucketCommand, PutBucketWebsiteCommand} from '@aws-sdk/client-s3';
import {s3Client} from './aws-clients';
import {bundleRemotion} from './bundle-remotion';
-import {LAMBDA_BUCKET_PREFIX, REGION} from './constants';
+import {LAMBDA_BUCKET_PREFIX} from './constants';
+import {makeS3Url} from './make-s3-url';
import {uploadDir, UploadDirProgress} from './upload-dir';
export const deploySite = async (
@@ -54,10 +55,8 @@ export const deploySite = async (
]);
// TODO: Do it with HTTPS, but wait for certificate
- const url = `http://${bucketName}.s3.${REGION}.amazonaws.com`;
-
return {
- url,
+ url: makeS3Url(bucketName),
bucketName,
};
};
diff --git a/packages/lambda/src/functions/renderer.ts b/packages/lambda/src/functions/renderer.ts
index 220196b077..e5e7c00be8 100644
--- a/packages/lambda/src/functions/renderer.ts
+++ b/packages/lambda/src/functions/renderer.ts
@@ -22,7 +22,7 @@ const renderHandler = async (params: LambdaPayload) => {
const browserInstance = await getBrowserInstance();
const outputDir = '/tmp/remotion-render-' + Math.random();
if (fs.existsSync(outputDir)) {
- (fs.rm ?? fs.rmdirSync)(outputDir);
+ (fs.rmSync ?? fs.rmdirSync)(outputDir);
}
lambdaWriteFile({
diff --git a/packages/lambda/src/make-s3-url.ts b/packages/lambda/src/make-s3-url.ts
new file mode 100644
index 0000000000..87994af3d4
--- /dev/null
+++ b/packages/lambda/src/make-s3-url.ts
@@ -0,0 +1,7 @@
+// TODO: Do it with HTTPS, but wait for certificate
+
+import {REGION} from './constants';
+
+export const makeS3Url = (bucketName: string): string => {
+ return `http://${bucketName}.s3.${REGION}.amazonaws.com`;
+};
diff --git a/packages/lambda/src/run.ts b/packages/lambda/src/run.ts
index 78553f1ba0..010e300a5b 100644
--- a/packages/lambda/src/run.ts
+++ b/packages/lambda/src/run.ts
@@ -2,17 +2,36 @@ import {CliInternals} from '@remotion/cli';
import {lambdaClient, s3Client} from './aws-clients';
import {callLambda} from './call-lambda';
import {checkLambdaStatus} from './check-lambda-status';
-import {cleanupLambdas} from './cleanup/cleanup-lambdas';
-import {cleanUpBuckets} from './cleanup/s3-buckets';
+import {cleanupLambdas, getRemotionLambdas} from './cleanup/cleanup-lambdas';
+import {cleanUpBuckets, getRemotionS3Buckets} from './cleanup/s3-buckets';
import {LambdaRoutines} from './constants';
import {createLambda} from './create-lambda';
+import {makeS3Url} from './make-s3-url';
import {sleep} from './sleep';
-CliInternals.xns(async () => {
- await cleanupLambdas({lambdaClient});
- await cleanUpBuckets({s3client: s3Client});
- const {functionName, bucketUrl} = await createLambda();
+const DEPLOY = false;
+
+const getFnName = async (): Promise<{
+ functionName: string;
+ bucketUrl: string;
+}> => {
+ if (DEPLOY) {
+ await cleanupLambdas({lambdaClient});
+ await cleanUpBuckets({s3client: s3Client});
+ const {functionName, bucketUrl} = await createLambda();
+ return {functionName, bucketUrl};
+ }
+ const lambdas = await getRemotionLambdas(lambdaClient);
+ const {remotionBuckets} = await getRemotionS3Buckets(s3Client);
+ return {
+ functionName: lambdas[0].FunctionName as string,
+ bucketUrl: makeS3Url(remotionBuckets[0] as string),
+ };
+};
+
+CliInternals.xns(async () => {
+ const {functionName, bucketUrl} = await getFnName();
const res = await callLambda({
functionName,
type: LambdaRoutines.start,