Skip to content

🎥 Make videos programmatically with React

functions command

Jonny Burgerd5fa6938dfb7
diff --git a/packages/docs/docs/lambda-cli.md b/packages/docs/docs/lambda-cli.md
index cd6c577a4a..8af197809c 100644
--- a/packages/docs/docs/lambda-cli.md
+++ b/packages/docs/docs/lambda-cli.md
@@ -67,5 +67,5 @@ npx remotion-lambda render https://remotionlambda-abcdefgh.s3.eu-central-1.amazo
Deploys a Remotion render lambda function to your account. You only need 1 function to render videos.
```
-npx remotion-lambda deploy
+npx remotion-lambda functions deploy
```
diff --git a/packages/docs/docs/lambda-setup.md b/packages/docs/docs/lambda-setup.md
index b255d426e6..e32d92e7e5 100644
--- a/packages/docs/docs/lambda-setup.md
+++ b/packages/docs/docs/lambda-setup.md
@@ -63,7 +63,7 @@ AWS_SECRET_ACCESS_KEY=xxx
## 7. Deploy a lambda
-- Run `npx remotion-lambda deploy`
+- Run `npx remotion-lambda functions deploy`
## 8. Deploy a website
diff --git a/packages/lambda/src/cli/commands/functions/deploy.ts b/packages/lambda/src/cli/commands/functions/deploy.ts
new file mode 100644
index 0000000000..b89c8580fa
--- /dev/null
+++ b/packages/lambda/src/cli/commands/functions/deploy.ts
@@ -0,0 +1,40 @@
+import {CliInternals} from '@remotion/cli';
+import {Log} from '@remotion/cli/dist/log';
+import {deployLambda} from '../../../api/deploy-lambda';
+import {ensureLambdaBinaries} from '../../../api/ensure-lambda-binaries';
+import {
+ CURRENT_VERSION,
+ DEFAULT_MEMORY_SIZE,
+ DEFAULT_TIMEOUT,
+} from '../../../shared/constants';
+import {validateMemorySize} from '../../../shared/validate-memory-size';
+import {validateTimeout} from '../../../shared/validate-timeout';
+import {parsedLambdaCli} from '../../args';
+import {getAwsRegion} from '../../get-aws-region';
+
+export const FUNCTIONS_DEPLOY_SUBCOMMAND = 'deploy';
+
+export const functionsDeploySubcommand = async () => {
+ const region = getAwsRegion();
+ const timeoutInSeconds = parsedLambdaCli.timeout ?? DEFAULT_TIMEOUT;
+ const memorySize = parsedLambdaCli.memory ?? DEFAULT_MEMORY_SIZE;
+ validateMemorySize(memorySize);
+ validateTimeout(timeoutInSeconds);
+ Log.info(
+ CliInternals.chalk.gray(
+ `Region = ${region}, Memory = ${memorySize}MB, Timeout = ${timeoutInSeconds}sec, Version = ${CURRENT_VERSION}`
+ )
+ );
+ const output = CliInternals.createOverwriteableCliOutput();
+ output.update('Ensuring Lambda binaries...');
+ // TODO: Output can be more finegrained
+ const {layerArn} = await ensureLambdaBinaries(getAwsRegion());
+ output.update('Bundling lambda and deploying...');
+ const {functionName} = await deployLambda({
+ region,
+ timeoutInSeconds,
+ layerArn,
+ memorySize,
+ });
+ output.update(`Deployed to ${functionName}\n`);
+};
diff --git a/packages/lambda/src/cli/commands/functions/index.ts b/packages/lambda/src/cli/commands/functions/index.ts
index 5ce65bdd34..9184949ca0 100644
--- a/packages/lambda/src/cli/commands/functions/index.ts
+++ b/packages/lambda/src/cli/commands/functions/index.ts
@@ -1,6 +1,7 @@
import {CliInternals} from '@remotion/cli';
import {Log} from '@remotion/cli/dist/log';
import {BINARY_NAME} from '../../../shared/constants';
+import {functionsDeploySubcommand, FUNCTIONS_DEPLOY_SUBCOMMAND} from './deploy';
import {functionsLsCommand, FUNCTIONS_LS_SUBCOMMAND} from './ls';
import {functionsRmCommand, FUNCTIONS_RM_SUBCOMMAND} from './rm';
@@ -14,6 +15,11 @@ const printFunctionsHelp = () => {
Log.info(`${BINARY_NAME} ${FUNCTIONS_COMMAND} ${FUNCTIONS_LS_SUBCOMMAND}`);
Log.info(CliInternals.chalk.gray('Lists the functions currently deployed'));
Log.info('');
+ Log.info(
+ `${BINARY_NAME} ${FUNCTIONS_COMMAND} ${FUNCTIONS_DEPLOY_SUBCOMMAND}`
+ );
+ Log.info(CliInternals.chalk.gray('Deploy a new Lambda function'));
+ Log.info('');
Log.info(
`${BINARY_NAME} ${FUNCTIONS_COMMAND} ${FUNCTIONS_RM_SUBCOMMAND} <function-name>`
);
@@ -29,6 +35,10 @@ export const functionsCommand = (args: string[]) => {
return functionsRmCommand(args.slice(1));
}
+ if (args[0] === FUNCTIONS_DEPLOY_SUBCOMMAND) {
+ return functionsDeploySubcommand();
+ }
+
if (args[0]) {
Log.error(`Subcommand ${args[0]} not found.`);
printFunctionsHelp();
diff --git a/packages/lambda/src/cli/deploy.ts b/packages/lambda/src/cli/deploy.ts
deleted file mode 100644
index 423bc67c01..0000000000
--- a/packages/lambda/src/cli/deploy.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import {deployLambda} from '../api/deploy-lambda';
-import {ensureLambdaBinaries} from '../api/ensure-lambda-binaries';
-import {DEFAULT_MEMORY_SIZE, DEFAULT_TIMEOUT} from '../shared/constants';
-import {parsedLambdaCli} from './args';
-import {getAwsRegion} from './get-aws-region';
-import {Log} from './log';
-
-export const DEPLOY_COMMAND = 'deploy';
-
-export const deployCommand = async () => {
- const timeoutInSeconds = parsedLambdaCli.timeout ?? DEFAULT_TIMEOUT;
- const memorySize = parsedLambdaCli.memory ?? DEFAULT_MEMORY_SIZE;
- const {layerArn} = await ensureLambdaBinaries(getAwsRegion());
- const {functionName} = await deployLambda({
- region: getAwsRegion(),
- timeoutInSeconds,
- layerArn,
- memorySize,
- });
- Log.info(`Deployed to ${functionName}`);
-};
diff --git a/packages/lambda/src/cli/help.ts b/packages/lambda/src/cli/help.ts
index d9b9f2093f..36aa3fcfbd 100644
--- a/packages/lambda/src/cli/help.ts
+++ b/packages/lambda/src/cli/help.ts
@@ -17,6 +17,7 @@ export const printHelp = () => {
Log.info();
Log.info('Available commands:');
Log.info('');
+
Log.info(`${BINARY_NAME} ${UPLOAD_COMMAND} <index-file.ts>`);
Log.info(CliInternals.chalk.gray('Upload a Remotion project to S3.'));
Log.info();
diff --git a/packages/lambda/src/cli/index.ts b/packages/lambda/src/cli/index.ts
index 6aacd11787..5bb575d981 100644
--- a/packages/lambda/src/cli/index.ts
+++ b/packages/lambda/src/cli/index.ts
@@ -2,7 +2,6 @@ import {CliInternals} from '@remotion/cli';
import {parsedLambdaCli} from './args';
import {cleanupCommand, CLEANUP_COMMAND} from './cleanup';
import {functionsCommand, FUNCTIONS_COMMAND} from './commands/functions';
-import {deployCommand, DEPLOY_COMMAND} from './deploy';
import {printHelp} from './help';
import {Log} from './log';
import {policiesCommand, POLICIES_COMMAND} from './policies';
@@ -15,10 +14,6 @@ const matchCommand = async () => {
process.exit(0);
}
- if (parsedLambdaCli._[0] === DEPLOY_COMMAND) {
- return deployCommand();
- }
-
if (parsedLambdaCli._[0] === UPLOAD_COMMAND) {
return uploadCommand();
}
diff --git a/packages/lambda/src/cli/render.ts b/packages/lambda/src/cli/render.ts
index 0c28b3a78b..863d735f67 100644
--- a/packages/lambda/src/cli/render.ts
+++ b/packages/lambda/src/cli/render.ts
@@ -6,7 +6,8 @@ import {BINARY_NAME} from '../shared/constants';
import {sleep} from '../shared/sleep';
import {parsedLambdaCli} from './args';
import {CLEANUP_COMMAND, CLEANUP_LAMBDAS_SUBCOMMAND} from './cleanup';
-import {DEPLOY_COMMAND} from './deploy';
+import {FUNCTIONS_COMMAND} from './commands/functions';
+import {FUNCTIONS_DEPLOY_SUBCOMMAND} from './commands/functions/deploy';
import {getAwsRegion} from './get-aws-region';
import {Log} from './log';
@@ -40,7 +41,9 @@ export const renderCommand = async () => {
if (remotionLambdas.length === 0) {
Log.error('No lambda functions found in your account.');
Log.info('Run');
- Log.info(` npx ${BINARY_NAME} ${DEPLOY_COMMAND}`);
+ Log.info(
+ ` npx ${BINARY_NAME} ${FUNCTIONS_COMMAND} ${FUNCTIONS_DEPLOY_SUBCOMMAND}`
+ );
Log.info(`to deploy a lambda function.`);
process.exit(1);
}
diff --git a/packages/lambda/src/functions/info.ts b/packages/lambda/src/functions/info.ts
index cae749f9c4..3edf944081 100644
--- a/packages/lambda/src/functions/info.ts
+++ b/packages/lambda/src/functions/info.ts
@@ -1,4 +1,5 @@
import {
+ CURRENT_VERSION,
LambdaPayload,
LambdaRoutines,
LambdaVersions,
@@ -12,7 +13,7 @@ export const infoHandler = async (lambdaParams: LambdaPayload) => {
const returnValue: {
version: LambdaVersions;
} = {
- version: '2021-06-23',
+ version: CURRENT_VERSION,
};
return returnValue;
diff --git a/packages/lambda/src/shared/constants.ts b/packages/lambda/src/shared/constants.ts
index b61acc4b35..f8871cd158 100644
--- a/packages/lambda/src/shared/constants.ts
+++ b/packages/lambda/src/shared/constants.ts
@@ -137,3 +137,4 @@ export type RenderMetadata = {
};
export type LambdaVersions = '2021-06-23' | 'n/a';
+export const CURRENT_VERSION: LambdaVersions = '2021-06-23';