Skip to content

🎥 Make videos programmatically with React

`@remotion/lambda`: Match custom output URLs to S3 addressing

Jonny Burger2bf0a12514e8
diff --git a/packages/docs/docs/lambda/rendermediaonlambda.mdx b/packages/docs/docs/lambda/rendermediaonlambda.mdx
index 751d61b35a..73214166b3 100644
--- a/packages/docs/docs/lambda/rendermediaonlambda.mdx
+++ b/packages/docs/docs/lambda/rendermediaonlambda.mdx
@@ -276,7 +276,7 @@ await renderMediaOnLambda({
});
```
-The filename extension selects the audio format: `.wav` uses PCM, `.aac`, `.m4a`, `.m4b` and `.3gp` use AAC, `.mp3` uses MP3, and `.opus` uses Opus. Existing [audio codec compatibility rules](/docs/audio-codec) apply. Conflicting `audioCodec` or `preferLossless` settings throw an error.
+The filename extension selects the audio format: `.wav` uses PCM, `.aac`, `.m4a`, `.m4b` and `.3gp` use AAC, `.mp3` uses MP3, and `.opus` uses Opus. Existing [audio codec compatibility rules](/docs/encoding/#audio-codec) apply. Conflicting `audioCodec` or `preferLossless` settings throw an error.
A composition without audio produces a silent audio file. Audio-only renders, codecs without audio support, and `muted: true` cannot be combined with this option. Both outputs use the specified privacy, storage class and overwrite behavior.
diff --git a/packages/lambda-client/src/get-output-url-from-metadata.ts b/packages/lambda-client/src/get-output-url-from-metadata.ts
index d74db99512..4101b3eac5 100644
--- a/packages/lambda-client/src/get-output-url-from-metadata.ts
+++ b/packages/lambda-client/src/get-output-url-from-metadata.ts
@@ -1,9 +1,12 @@
+import {S3Client} from '@aws-sdk/client-s3';
import type {GetOutputUrl} from '@remotion/serverless-client';
import {getExpectedOutName} from '@remotion/serverless-client';
import type {AwsProvider} from './aws-provider';
import {getAwsRegionMetadata} from './aws-region-metadata';
import {REMOTION_BUCKET_PREFIX} from './constants';
+const {endpointProvider} = new S3Client({region: 'us-east-1'}).config;
+
export const getOutputUrlFromMetadata: GetOutputUrl<AwsProvider> = ({
renderMetadata,
bucketName,
@@ -23,12 +26,23 @@ export const getOutputUrlFromMetadata: GetOutputUrl<AwsProvider> = ({
output,
});
if (credentials !== null) {
- const url = new URL(credentials.endpoint);
- if (!credentials.forcePathStyle) {
- url.hostname = `${renderBucketName}.${url.hostname}`;
- }
-
- url.pathname = `${url.pathname.replace(/\/$/, '')}/${credentials.forcePathStyle ? `${renderBucketName}/` : ''}${key.split('/').map(encodeURIComponent).join('/')}`;
+ const url = new URL(
+ endpointProvider(
+ {
+ Bucket: renderBucketName,
+ Endpoint: credentials.endpoint,
+ Region: credentials.region ?? currentRegion,
+ // The SDK's S3 middleware also forces path style for dotted buckets.
+ ForcePathStyle:
+ credentials.forcePathStyle === true ||
+ renderBucketName.includes('.'),
+ UseFIPS: false,
+ UseDualStack: false,
+ },
+ {},
+ ).url,
+ );
+ url.pathname = `${url.pathname.replace(/\/$/, '')}/${key.split('/').map(encodeURIComponent).join('/')}`;
return {url: url.toString(), key};
}
diff --git a/packages/serverless-client/src/constants.ts b/packages/serverless-client/src/constants.ts
index 6f6ee86ad7..f354c1141f 100644
--- a/packages/serverless-client/src/constants.ts
+++ b/packages/serverless-client/src/constants.ts
@@ -45,6 +45,7 @@ export enum ServerlessRoutines {
export type CustomCredentialsWithoutSensitiveData = {
endpoint: string;
+ forcePathStyle?: boolean;
};
export type CustomCredentials<Provider extends CloudProvider> =
@@ -52,7 +53,6 @@ export type CustomCredentials<Provider extends CloudProvider> =
accessKeyId: string | null;
secretAccessKey: string | null;
region?: Provider['region'] | (string & {});
- forcePathStyle?: boolean;
};
export type OutNameInput<Provider extends CloudProvider> =
diff --git a/packages/serverless-client/src/get-custom-out-name.ts b/packages/serverless-client/src/get-custom-out-name.ts
index 6f0e055ebe..43584dd5b3 100644
--- a/packages/serverless-client/src/get-custom-out-name.ts
+++ b/packages/serverless-client/src/get-custom-out-name.ts
@@ -38,7 +38,10 @@ export const getCustomOutName = <Provider extends CloudProvider>({
accessKeyId: customCredentials?.accessKeyId ?? null,
secretAccessKey: customCredentials?.secretAccessKey ?? null,
region: customCredentials?.region,
- forcePathStyle: customCredentials?.forcePathStyle ?? false,
+ forcePathStyle:
+ outName.s3OutputProvider.forcePathStyle ??
+ customCredentials?.forcePathStyle ??
+ false,
},
};
}
diff --git a/packages/serverless/src/handlers/launch.ts b/packages/serverless/src/handlers/launch.ts
index 746876d4f7..4d5b2b8e05 100644
--- a/packages/serverless/src/handlers/launch.ts
+++ b/packages/serverless/src/handlers/launch.ts
@@ -89,6 +89,7 @@ const innerLaunchHandler = async <Provider extends CloudProvider>({
if (params.codec !== null) {
validateCodec(params.codec, 'renderMediaOnLambda', 'codec');
}
+
const separateAudioTo = params.separateAudioTo ?? null;
if (separateAudioTo !== null && params.codec === null) {
diff --git a/packages/serverless/src/remove-outname-credentials.ts b/packages/serverless/src/remove-outname-credentials.ts
index 85081cfed6..296699c5bb 100644
--- a/packages/serverless/src/remove-outname-credentials.ts
+++ b/packages/serverless/src/remove-outname-credentials.ts
@@ -21,6 +21,7 @@ export const removeOutnameCredentials = <Provider extends CloudProvider>(
s3OutputProvider: outname.s3OutputProvider
? {
endpoint: outname.s3OutputProvider.endpoint,
+ forcePathStyle: outname.s3OutputProvider.forcePathStyle ?? false,
}
: undefined,
};