Skip to content

Commit

Permalink
Merge pull request #4813 from remotion-dev/lambda-api-key
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyBurger authored Jan 26, 2025
2 parents c082263 + ab6f93f commit ec07e26
Show file tree
Hide file tree
Showing 28 changed files with 159 additions and 30 deletions.
4 changes: 4 additions & 0 deletions packages/docs/docs/lambda/cli/render.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,7 @@ Lets you set a custom user agent that the headless Chrome browser assumes.
### `--force-path-style`<AvailableFrom v="4.0.202" />

Passes `forcePathStyle` to the AWS S3 client. If you don't know what this is, you probably don't need it.

### `--api-Key`<AvailableFrom v="4.0.253"/>

<Options id="api-key" />
10 changes: 7 additions & 3 deletions packages/docs/docs/lambda/cli/still.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
image: /generated/articles-docs-lambda-cli-still.png
id: still
sidebar_label: still
title: "npx remotion lambda still"
title: 'npx remotion lambda still'
slug: /lambda/cli/still
crumb: "Lambda CLI Reference"
crumb: 'Lambda CLI Reference'
---

Using the `npx remotion lambda still` command, you can render a still frame in the cloud.
Expand Down Expand Up @@ -116,8 +116,12 @@ Lets you set a custom user agent that the headless Chrome browser assumes.

### `--delete-after`<AvailableFrom v="4.0.32"/>

<Options id="delete-after" cli/>
<Options id="delete-after" cli />

### `--force-path-style`<AvailableFrom v="4.0.202" />

Passes `forcePathStyle` to the AWS S3 client. If you don't know what this is, you probably don't need it.

### `apiKey?`<AvailableFrom v="4.0.253"/>

<Options id="api-key" />
7 changes: 5 additions & 2 deletions packages/docs/docs/lambda/rendermediaonlambda.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ const {bucketName, renderId} = await renderMediaOnLambda({
region: 'us-east-1',
functionName: 'remotion-render-bds9aab',
composition: 'MyVideo',
serveUrl:
'https://remotionlambda-qg35eyp1s1.s3.eu-central-1.amazonaws.com/sites/bf2jrbfkw',
serveUrl: 'https://remotionlambda-qg35eyp1s1.s3.eu-central-1.amazonaws.com/sites/bf2jrbfkw',
codec: 'h264',
});
```
Expand Down Expand Up @@ -370,6 +369,10 @@ If the `logLevel` is set to `verbose`, the Lambda function will not clean up art

Passes `forcePathStyle` to the AWS S3 client. If you don't know what this is, you probably don't need it.

### `apiKey?`<AvailableFrom v="4.0.253"/>

<Options id="api-key" />

### ~~`dumpBrowserLogs?`~~

_optional - default `false`, deprecated in v4.0_
Expand Down
44 changes: 21 additions & 23 deletions packages/docs/docs/lambda/renderstillonlambda.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ image: /generated/articles-docs-lambda-renderstillonlambda.png
id: renderstillonlambda
title: renderStillOnLambda()
slug: /lambda/renderstillonlambda
crumb: "Lambda API"
crumb: 'Lambda API'
---

Renders a still image inside a lambda function and writes it to the specified output location.
Expand All @@ -17,18 +17,17 @@ If you want to render a still locally instead, use [`renderStill()`](/docs/rende
```tsx twoslash
// @module: esnext
// @target: es2017
import { renderStillOnLambda } from "@remotion/lambda/client";

const { estimatedPrice, url, sizeInBytes } = await renderStillOnLambda({
region: "us-east-1",
functionName: "remotion-render-bds9aab",
serveUrl:
"https://remotionlambda-qg35eyp1s1.s3.eu-central-1.amazonaws.com/sites/bf2jrbfkw",
composition: "MyVideo",
import {renderStillOnLambda} from '@remotion/lambda/client';

const {estimatedPrice, url, sizeInBytes} = await renderStillOnLambda({
region: 'us-east-1',
functionName: 'remotion-render-bds9aab',
serveUrl: 'https://remotionlambda-qg35eyp1s1.s3.eu-central-1.amazonaws.com/sites/bf2jrbfkw',
composition: 'MyVideo',
inputProps: {},
imageFormat: "png",
imageFormat: 'png',
maxRetries: 1,
privacy: "public",
privacy: 'public',
envVariables: {},
frame: 10,
});
Expand Down Expand Up @@ -104,27 +103,23 @@ Example usage:
// @module: esnext
// @target: es2022

import {
renderStillOnLambda,
RenderStillOnLambdaInput,
} from "@remotion/lambda/client";
import {renderStillOnLambda, RenderStillOnLambdaInput} from '@remotion/lambda/client';

const otherParameters: RenderStillOnLambdaInput = {
region: "us-east-1",
functionName: "remotion-render-bds9aab",
serveUrl:
"https://remotionlambda-qg35eyp1s1.s3.eu-central-1.amazonaws.com/sites/bf2jrbfkw",
composition: "MyVideo",
region: 'us-east-1',
functionName: 'remotion-render-bds9aab',
serveUrl: 'https://remotionlambda-qg35eyp1s1.s3.eu-central-1.amazonaws.com/sites/bf2jrbfkw',
composition: 'MyVideo',
inputProps: {},
imageFormat: "png",
imageFormat: 'png',
maxRetries: 1,
privacy: "public",
privacy: 'public',
envVariables: {},
frame: 10,
};
await renderStillOnLambda({
...otherParameters,
onInit: ({ cloudWatchLogs, renderId, lambdaInsightsUrl }) => {
onInit: ({cloudWatchLogs, renderId, lambdaInsightsUrl}) => {
console.log(console.log(`Render invoked with ID = ${renderId}`));
console.log(`CloudWatch logs (if enabled): ${cloudWatchLogs}`);
console.log(`Lambda Insights (if enabled): ${lambdaInsightsUrl}`);
Expand Down Expand Up @@ -262,6 +257,9 @@ _optional - default `false`, deprecated in v4.0_

Deprecated in favor of [`logLevel`](#loglevel).

### `apiKey?`<AvailableFrom v="4.0.253"/>

<Options id="api-key" />

## Return value

Expand Down
2 changes: 1 addition & 1 deletion packages/example/runlambda.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ cd example
bunx remotion lambda functions rmall -f
bunx remotion lambda functions deploy --memory=3000 --disk=10000
bunx remotion lambda sites create --site-name=testbed-v6 --log=verbose --enable-folder-expiry
bunx remotion lambda render testbed-v6 OffthreadRemoteVideo --log=verbose --delete-after="1-day"
bunx remotion lambda render testbed-v6 OffthreadRemoteVideo --log=verbose --delete-after="1-day" --api-key=rm_pub_9a996d341238eaa34e696b099968d8510420b9f6ba4aa0ee
2 changes: 2 additions & 0 deletions packages/it-tests/src/monorepo/ruby-package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ test('Render Media payload', async () => {
metadata: {
Author: 'Lunar',
},
apiKey: null,
});

expect(JSON.parse(output)).toEqual(nativeVersion);
Expand Down Expand Up @@ -172,6 +173,7 @@ test('Render Still payload', async () => {
dumpBrowserLogs: false,
quality: undefined,
forcePathStyle: false,
apiKey: null,
});

expect(JSON.parse(output)).toEqual({...nativeVersion, streamed: false});
Expand Down
1 change: 1 addition & 0 deletions packages/lambda-go/internalops.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func constructRenderInternals(options *RemotionOptions) (*renderInternalOptions,
OffthreadVideoCacheSizeInBytes: options.OffthreadVideoCacheSizeInBytes,
X264Preset: options.X264Preset,
ForceWidth: options.ForceWidth,
ApiKey: options.ApiKey,
BucketName: options.BucketName,
AudioCodec: options.AudioCodec,
ForceBucketName: options.ForceBucketName,
Expand Down
2 changes: 2 additions & 0 deletions packages/lambda-go/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type RemotionOptions struct {
ForceHeight interface{} `json:"forceHeight"`
OffthreadVideoCacheSizeInBytes interface{} `json:"offthreadVideoCacheSizeInBytes"`
ForceWidth interface{} `json:"forceWidth"`
ApiKey interface{} `json:"apiKey"`
BucketName interface{} `json:"bucketName"`
AudioCodec interface{} `json:"audioCodec"`
ForceBucketName string `json:"forceBucketName"`
Expand Down Expand Up @@ -87,6 +88,7 @@ type renderInternalOptions struct {
OffthreadVideoCacheSizeInBytes interface{} `json:"offthreadVideoCacheSizeInBytes"`
ForceHeight interface{} `json:"forceHeight"`
ForceWidth interface{} `json:"forceWidth"`
ApiKey interface{} `json:"apiKey"`
BucketName interface{} `json:"bucketName"`
AudioCodec interface{} `json:"audioCodec"`

Expand Down
14 changes: 14 additions & 0 deletions packages/lambda-php/src/RenderParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class RenderParams
protected $webhook = null;
protected $forceHeight = null;
protected $forceWidth = null;
protected $apiKey = null;
protected $offthreadVideoCacheSizeInBytes = null;
protected $audioCodec = null;
protected $rendererFunctionName = null;
Expand Down Expand Up @@ -83,6 +84,7 @@ public function __construct(
?string $webhook = null,
?int $forceHeight = null,
?int $forceWidth = null,
?int $apiKey = null,
?int $offthreadVideoCacheSizeInBytes = null,
?string $audioCodec = null,
?int $framesPerLambda = null,
Expand Down Expand Up @@ -133,6 +135,7 @@ public function __construct(
$this->webhook = $webhook;
$this->forceHeight = $forceHeight;
$this->forceWidth = $forceWidth;
$this->apiKey = $apiKey;
$this->offthreadVideoCacheSizeInBytes = $offthreadVideoCacheSizeInBytes;
$this->audioCodec = $audioCodec;
$this->framesPerLambda = $framesPerLambda;
Expand Down Expand Up @@ -182,6 +185,7 @@ public function serializeParams()
'webhook' => $this->getWebhook(),
'forceHeight' => $this->getForceHeight(),
'forceWidth' => $this->getForceWidth(),
'apiKey' => $this->getApiKey(),
'offthreadVideoCacheSizeInBytes' => $this->getOffthreadVideoCacheSizeInBytes(),
'bucketName' => $this->getBucketName(),
'audioCodec' => $this->getAudioCodec(),
Expand Down Expand Up @@ -702,6 +706,11 @@ public function setForceWidth($forceWidth)
$this->forceWidth = $forceWidth;
}

public function setApiKey($apiKey)
{
$this->apiKey = $apiKey;
}

public function setOffthreadVideoCacheSizeInBytes($offthreadVideoCacheSizeInBytes)
{
$this->offthreadVideoCacheSizeInBytes = $offthreadVideoCacheSizeInBytes;
Expand Down Expand Up @@ -758,6 +767,11 @@ public function getForceWidth()
return $this->forceWidth;
}

public function getApiKey()
{
return $this->apiKey;
}

public function getOffthreadVideoCacheSizeInBytes()
{
return $this->offthreadVideoCacheSizeInBytes;
Expand Down
4 changes: 4 additions & 0 deletions packages/lambda-python/remotion_lambda/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ class RenderMediaParams:
force_height: Optional[int] = None
offthreadvideo_cache_size_in_bytes: Optional[int] = None
force_width: Optional[int] = None
api_key: Optional[str] = None
audio_codec: Optional[str] = None
renderer_function_name: Optional[str] = None
pro_res_profile: Optional[str] = None
Expand Down Expand Up @@ -358,6 +359,7 @@ def serialize_params(self) -> Dict:
'forceHeight': self.force_height,
'offthreadVideoCacheSizeInBytes': self.offthreadvideo_cache_size_in_bytes,
'forceWidth': self.force_width,
'apiKey': self.api_key,
'bucketName': self.bucket_name,
'audioCodec': self.audio_codec,
'x264Preset': self.x264_preset,
Expand Down Expand Up @@ -422,6 +424,7 @@ class RenderStillParams:
download_behavior: Dict = field(default_factory=lambda: {
'type': 'play-in-browser'})
force_width: Optional[int] = None
api_key: Optional[int] = None
force_height: Optional[int] = None
force_bucket_name: Optional[str] = None
dump_browser_logs: Optional[bool] = None
Expand Down Expand Up @@ -467,6 +470,7 @@ def serialize_params(self) -> Dict:
'scale': self.scale,
'downloadBehavior': self.download_behavior or {'type': 'play-in-browser'},
'forceWidth': self.force_width,
'apiKey': self.api_key,
'forceHeight': self.force_height,
'forceBucketName': self.force_bucket_name,
'deleteAfter': self.delete_after,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def get_render_media_on_lambda_payload(
force_height: nil,
force_path_style: false,
force_width: nil,
api_key: nil,
frame_range: nil,
frames_per_lambda: nil,
image_format: "jpeg",
Expand Down Expand Up @@ -63,6 +64,7 @@ def get_render_media_on_lambda_payload(
forceHeight: force_height,
forcePathStyle: force_path_style,
forceWidth: force_width,
apiKey: api_key,
frameRange: frame_range,
framesPerLambda: frames_per_lambda,
imageFormat: image_format,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def get_render_still_on_lambda_payload(
force_height: nil,
force_path_style: false,
force_width: nil,
api_key: nil,
image_format: "jpeg",
input_props: {},
jpeg_quality: 80,
Expand All @@ -35,6 +36,7 @@ def get_render_still_on_lambda_payload(
forceHeight: force_height,
forcePathStyle: force_path_style,
forceWidth: force_width,
apiKey: api_key,
imageFormat: image_format,
inputProps: {
type: "payload",
Expand Down
4 changes: 4 additions & 0 deletions packages/lambda/src/api/make-lambda-payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export const makeLambdaRenderMediaPayload = async ({
preferLossless,
forcePathStyle,
metadata,
apiKey,
}: InnerRenderMediaOnLambdaInput): Promise<
ServerlessStartPayload<AwsProvider>
> => {
Expand Down Expand Up @@ -211,6 +212,7 @@ export const makeLambdaRenderMediaPayload = async ({
preferLossless: preferLossless ?? false,
forcePathStyle: forcePathStyle ?? false,
metadata: metadata ?? null,
apiKey: apiKey ?? null,
};
};

Expand Down Expand Up @@ -256,6 +258,7 @@ export const makeLambdaRenderStillPayload = async ({
offthreadVideoCacheSizeInBytes,
deleteAfter,
forcePathStyle,
apiKey,
}: RenderStillOnLambdaNonNullInput): Promise<
ServerlessPayloads<AwsProvider>[ServerlessRoutines.still]
> => {
Expand Down Expand Up @@ -311,5 +314,6 @@ export const makeLambdaRenderStillPayload = async ({
type: ServerlessRoutines.still,
streamed: true,
forcePathStyle,
apiKey: apiKey ?? null,
};
};
1 change: 1 addition & 0 deletions packages/lambda/src/api/render-media-on-lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ export const renderMediaOnLambdaOptionalToRequired = (
forcePathStyle: options.forcePathStyle ?? false,
indent: false,
metadata: options.metadata ?? null,
apiKey: options.apiKey ?? null,
};
};

Expand Down
1 change: 1 addition & 0 deletions packages/lambda/src/api/render-still-on-lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,6 @@ export const renderStillOnLambda = (input: RenderStillOnLambdaInput) => {
timeoutInMilliseconds: input.timeoutInMilliseconds ?? 30000,
dumpBrowserLogs: false,
forcePathStyle: input.forcePathStyle ?? false,
apiKey: input.apiKey ?? null,
});
};
2 changes: 2 additions & 0 deletions packages/lambda/src/cli/commands/render/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ export const renderCommand = async ({
indent: false,
forcePathStyle: parsedLambdaCli['force-path-style'] ?? false,
metadata: metadata ?? null,
apiKey:
parsedLambdaCli[BrowserSafeApis.options.apiKeyOption.cliFlag] ?? null,
});

const progressBar = CliInternals.createOverwriteableCliOutput({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ test('Should fail when using an incompatible version', async () => {
preferLossless: false,
forcePathStyle: false,
metadata: {Author: 'Lunar'},
apiKey: null,
},
functionName: 'remotion-dev-render',
region: 'us-east-1',
Expand Down
2 changes: 2 additions & 0 deletions packages/lambda/src/test/integration/webhooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ test('Should call webhook upon completion', async () => {
preferLossless: false,
forcePathStyle: false,
metadata: {Author: 'Lunar'},
apiKey: null,
},
functionName: 'remotion-dev-lambda',
region: 'us-east-1',
Expand Down Expand Up @@ -207,6 +208,7 @@ test('Should call webhook upon timeout', async () => {
preferLossless: false,
forcePathStyle: false,
metadata: null,
apiKey: null,
},
timeoutInTest: 1000,
});
Expand Down
Loading

0 comments on commit ec07e26

Please sign in to comment.