🎥 Make videos programmatically with React
feat+docs(lambda): `speculateFunctionName` fn
Mohit Yadav19396b799a4c
diff --git a/packages/docs/components/TableOfContents/lambda.tsx b/packages/docs/components/TableOfContents/lambda.tsxindex eff0d13416..e62c4d65ed 100644--- a/packages/docs/components/TableOfContents/lambda.tsx+++ b/packages/docs/components/TableOfContents/lambda.tsx@@ -86,6 +86,10 @@ export const TableOfContents: React.FC = () => {<strong>simulatePermissions()</strong><div>Ensure permissions are correctly set up</div></TOCItem>+ <TOCItem link="/docs/lambda/speculatefunctionname">+ <strong>speculateFunctionName()</strong>+ <div>Get the lambda function name based on its configuration</div>+ </TOCItem><TOCItem link="/docs/lambda/validatewebhooksignature"><strong>validateWebhookSignature()</strong><div>Validate an incoming webhook request is authentic</div>diff --git a/packages/docs/docs/lambda/speculateFunctionName.md b/packages/docs/docs/lambda/speculateFunctionName.mdnew file mode 100644index 0000000000..1dd601f5d0--- /dev/null+++ b/packages/docs/docs/lambda/speculateFunctionName.md@@ -0,0 +1,72 @@+---+image: /generated/articles-docs-lambda-speculateFunctionName.png+id: speculatefunctionname+title: speculateFunctionName()+slug: /lambda/speculatefunctionname+crumb: "Lambda API"+---++Speculate the name of the Lambda function that will be created by [deployFunction()](/docs/lambda/deployfunction) or its CLI equivalent, [`npx remotion lambda functions deploy`](/docs/lambda/cli/functions). This could be useful in cases when the configuration of the Lambda function is known in advance, and the name of the function is needed.++## Function name pattern++The function name depends on the following parameters:++- Remotion version+- Memory size+- Disk size+- Timeout++The name of the function resembles the following pattern:++```+remotion-render-3-3-63-mem2048mb-disk2048mb-240sec+ ^^^^^^ ^^^^ ^^^ ^^^+ | | | |-- Timeout in seconds+ | | |--------- Disk size in MB+ | |------------------- Memory size in MB+ |----------------------------- Remotion version with dots replaced by dashes+```++## Example++```ts twoslash+// @module: esnext+// @target: es2017++import { speculateFunctionName } from "@remotion/lambda/client";++const speculatedFunctionName = await speculateFunctionName({+ memorySizeInMb: 2048,+ diskSizeInMb: 2048,+ timeoutInSeconds: 120,+});++console.log(speculatedFunctionName); // remotion-render-3-3-63-mem2048mb-disk2048mb-120sec+```++## Arguments++An object with the following properties:++### `memorySizeInMb`++The amount of memory allocated to the function.++### `diskSizeInMb`++The amount of disk space allocated to the function.++### `timeoutInSeconds`++The timeout that has been assigned to the Lambda function.++## Return value++A string with the name of the function that will be created.++## See also++- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/lambda/src/api/speculate-function-name.ts)+- [deployFunction()](/docs/lambda/deployfunction)+- CLI version of `deployFunction()`: [`npx remotion lambda functions deploy`](/docs/lambda/cli/functions#deploy)diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.jsindex a83d48fe57..dc12484435 100644--- a/packages/docs/sidebars.js+++ b/packages/docs/sidebars.js@@ -194,6 +194,7 @@ module.exports = {"lambda/rendermediaonlambda","lambda/renderstillonlambda","lambda/simulatepermissions",+ "lambda/speculatefunctionname","lambda/validatewebhooksignature",],},diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.tsindex 0cafddc0bb..b748d5ef18 100644--- a/packages/docs/src/data/articles.ts+++ b/packages/docs/src/data/articles.ts@@ -867,6 +867,13 @@ export const articles = [compId: "articles-docs-lambda-simulatepermissions",crumb: "Lambda API",},+ {+ id: "speculatefunctionname",+ title: "speculateFunctionName()",+ relativePath: "docs/lambda/speculateFunctionName.md",+ compId: "articles-docs-lambda-speculateFunctionName",+ crumb: "Lambda API",+ },{id: "optimizing-speed",title: "Optimizing for speed",diff --git a/packages/docs/static/generated/articles-docs-lambda-speculateFunctionName.png b/packages/docs/static/generated/articles-docs-lambda-speculateFunctionName.pngnew file mode 100644index 0000000000..a9faeda52aBinary files /dev/null and b/packages/docs/static/generated/articles-docs-lambda-speculateFunctionName.png differdiff --git a/packages/lambda/src/api/speculate-function-name.ts b/packages/lambda/src/api/speculate-function-name.tsnew file mode 100644index 0000000000..1a52abc9dd--- /dev/null+++ b/packages/lambda/src/api/speculate-function-name.ts@@ -0,0 +1,29 @@+import {RENDER_FN_PREFIX} from '../defaults';+import {LAMBDA_VERSION_STRING} from '../shared/lambda-version-string';++export type SpeculateFunctionNameInput = {+ memorySizeInMb: string | number;+ diskSizeInMb: string | number;+ timeoutInSeconds: string | number;+};++/**+ * @description Speculate the name of a lambda function that will be created when you call `deployFunction`, based on the function configuration.+ * @see [Documentation](https://www.remotion.dev/docs/lambda/speculatefunctionname)+ * @param options.memorySizeInMb How much memory is allocated to the Lambda function.+ * @param options.diskSizeInMb The amount of storage the function is allocated.+ * @param options.timeoutInSeconds Time in seconds until the function times out.+ * @returns {string} The speculated lambda function name+ */+export const speculateFunctionName = ({+ memorySizeInMb,+ diskSizeInMb,+ timeoutInSeconds,+}: SpeculateFunctionNameInput) => {+ return [+ `${RENDER_FN_PREFIX}${LAMBDA_VERSION_STRING}`,+ `mem${memorySizeInMb}mb`,+ `disk${diskSizeInMb}mb`,+ `${timeoutInSeconds}sec`,+ ].join('-');+};diff --git a/packages/lambda/src/client.ts b/packages/lambda/src/client.tsindex 9bbc5a5455..192d3126ab 100644--- a/packages/lambda/src/client.ts+++ b/packages/lambda/src/client.ts@@ -9,6 +9,8 @@ import {renderVideoOnLambda,} from './api/render-media-on-lambda';import {renderStillOnLambda} from './api/render-still-on-lambda';+import type {SpeculateFunctionNameInput} from './api/speculate-function-name';+import {speculateFunctionName} from './api/speculate-function-name';import {validateWebhookSignature} from './api/validate-webhook-signature';import type {AwsRegion} from './pricing/aws-regions';import type {RenderProgress} from './shared/constants';@@ -24,5 +26,12 @@ export {getCompositionsOnLambda,presignUrl,getSites,+ speculateFunctionName,+};+export type {+ AwsRegion,+ RenderProgress,+ SpeculateFunctionNameInput,+ WebhookPayload,+ PresignUrlInput,};-export type {AwsRegion, RenderProgress, WebhookPayload, PresignUrlInput};