🎥 Make videos programmatically with React
customS3credentials
Jonny Burgera66edfe908f1
diff --git a/packages/lambda/src/api/bucket-exists.ts b/packages/lambda/src/api/bucket-exists.tsindex 5e9422fa7b..6360bf8ecf 100644--- a/packages/lambda/src/api/bucket-exists.ts+++ b/packages/lambda/src/api/bucket-exists.ts@@ -12,7 +12,7 @@ export const bucketExistsInRegion = async ({expectedBucketOwner: string | null;}) => {try {- const bucket = await getS3Client(region).send(+ const bucket = await getS3Client(region, null).send(new GetBucketLocationCommand({Bucket: bucketName,ExpectedBucketOwner: expectedBucketOwner ?? undefined,diff --git a/packages/lambda/src/api/clean-items.ts b/packages/lambda/src/api/clean-items.tsindex cba90808d7..f9a559f4dd 100644--- a/packages/lambda/src/api/clean-items.ts+++ b/packages/lambda/src/api/clean-items.ts@@ -25,7 +25,7 @@ export const cleanItems = async ({bucketName: bucket,itemName: object,});- await getS3Client(region).send(+ await getS3Client(region, null).send(new DeleteObjectCommand({Bucket: bucket,Key: object,diff --git a/packages/lambda/src/api/create-bucket.ts b/packages/lambda/src/api/create-bucket.tsindex eeadd5c265..f8f97f622e 100644--- a/packages/lambda/src/api/create-bucket.ts+++ b/packages/lambda/src/api/create-bucket.ts@@ -9,7 +9,7 @@ export const createBucket = async ({region: AwsRegion;bucketName: string;}) => {- await getS3Client(region).send(+ await getS3Client(region, null).send(new CreateBucketCommand({Bucket: bucketName,ACL: 'public-read',diff --git a/packages/lambda/src/api/enable-s3-website.ts b/packages/lambda/src/api/enable-s3-website.tsindex 06f1d97e47..d2c16c4c0f 100644--- a/packages/lambda/src/api/enable-s3-website.ts+++ b/packages/lambda/src/api/enable-s3-website.ts@@ -9,7 +9,7 @@ export const enableS3Website = async ({region: AwsRegion;bucketName: string;}) => {- await getS3Client(region).send(+ await getS3Client(region, null).send(new PutBucketWebsiteCommand({Bucket: bucketName,WebsiteConfiguration: {diff --git a/packages/lambda/src/api/get-aws-client.ts b/packages/lambda/src/api/get-aws-client.tsindex c88b8d3bc2..89ef41e445 100644--- a/packages/lambda/src/api/get-aws-client.ts+++ b/packages/lambda/src/api/get-aws-client.ts@@ -4,12 +4,13 @@ import * as LambdaSDK from '@aws-sdk/client-lambda';import * as S3SDK from '@aws-sdk/client-s3';import * as ServiceQuotasSDK from '@aws-sdk/client-service-quotas';import type {AwsRegion} from '../client';-import type { ServiceMapping} from '../shared/aws-clients';+import type {CustomCredentials, ServiceMapping} from '../shared/aws-clients';import {getServiceClient} from '../shared/aws-clients';export type GetAwsClientInput<T extends keyof ServiceMapping> = {region: AwsRegion;service: T;+ customCredentials?: CustomCredentials | null;};type SdkMapping = {@@ -35,9 +36,14 @@ export type GetAwsClientOutput<T extends keyof ServiceMapping> = {export const getAwsClient = <T extends keyof ServiceMapping>({region,service,+ customCredentials,}: GetAwsClientInput<T>): GetAwsClientOutput<T> => {return {- client: getServiceClient(region, service),+ client: getServiceClient({+ region,+ service,+ customCredentials: customCredentials ?? null,+ }),sdk: {lambda: LambdaSDK,cloudwatch: CloudWatchSDK,diff --git a/packages/lambda/src/api/get-buckets.ts b/packages/lambda/src/api/get-buckets.tsindex df573e69f5..1696f0fb87 100644--- a/packages/lambda/src/api/get-buckets.ts+++ b/packages/lambda/src/api/get-buckets.ts@@ -14,7 +14,9 @@ export const getRemotionS3Buckets = async (): Promise<{remotionBuckets: BucketWithLocation[];}> => {- const {Buckets} = await getS3Client(region).send(new ListBucketsCommand({}));+ const {Buckets} = await getS3Client(region, null).send(+ new ListBucketsCommand({})+ );if (!Buckets) {return {remotionBuckets: []};}@@ -25,7 +27,7 @@ export const getRemotionS3Buckets = async (const locations = await Promise.all(remotionBuckets.map((bucket) => {- return getS3Client(region).send(+ return getS3Client(region, null).send(new GetBucketLocationCommand({Bucket: bucket.Name as string,})diff --git a/packages/lambda/src/api/presign-url.ts b/packages/lambda/src/api/presign-url.tsindex a1d4d0189c..4889d86a17 100644--- a/packages/lambda/src/api/presign-url.ts+++ b/packages/lambda/src/api/presign-url.ts@@ -33,7 +33,7 @@ export const presignUrl = async ({validateBucketName(bucketName, {mustStartWithRemotion: false});validatePresignExpiration(expiresInSeconds);- const s3Client = getS3Client(region);+ const s3Client = getS3Client(region, null);if (checkIfObjectExists) {try {diff --git a/packages/lambda/src/api/upload-dir.ts b/packages/lambda/src/api/upload-dir.tsindex e076e8134d..2fba3420fa 100644--- a/packages/lambda/src/api/upload-dir.ts+++ b/packages/lambda/src/api/upload-dir.ts@@ -71,7 +71,7 @@ export const uploadDir = async ({progresses[file.name] = 0;}- const client = getS3Client(region);+ const client = getS3Client(region, null);const uploads = files.map(async (filePath) => {const Key = makeS3Key(folder, dir, filePath.name);diff --git a/packages/lambda/src/cli/commands/quotas/increase.ts b/packages/lambda/src/cli/commands/quotas/increase.tsindex be84714c39..9627df3003 100644--- a/packages/lambda/src/cli/commands/quotas/increase.ts+++ b/packages/lambda/src/cli/commands/quotas/increase.ts@@ -20,19 +20,19 @@ export const quotasIncreaseCommand = async () => {const [concurrencyLimit, defaultConcurrencyLimit, changes] =await Promise.all([- getServiceQuotasClient(region).send(+ getServiceQuotasClient(region, null).send(new GetServiceQuotaCommand({QuotaCode: LAMBDA_CONCURRENCY_LIMIT_QUOTA,ServiceCode: 'lambda',})),- getServiceQuotasClient(region).send(+ getServiceQuotasClient(region, null).send(new GetAWSDefaultServiceQuotaCommand({QuotaCode: LAMBDA_CONCURRENCY_LIMIT_QUOTA,ServiceCode: 'lambda',})),- getServiceQuotasClient(region).send(+ getServiceQuotasClient(region, null).send(new ListRequestedServiceQuotaChangeHistoryByQuotaCommand({QuotaCode: LAMBDA_CONCURRENCY_LIMIT_QUOTA,ServiceCode: 'lambda',@@ -71,7 +71,7 @@ export const quotasIncreaseCommand = async () => {allowForceFlag: true,delMessage: 'Send? (Y/n)',});- await getServiceQuotasClient(region).send(+ await getServiceQuotasClient(region, null).send(new RequestServiceQuotaIncreaseCommand({QuotaCode: LAMBDA_CONCURRENCY_LIMIT_QUOTA,DesiredValue: newLimit,diff --git a/packages/lambda/src/cli/commands/quotas/list.ts b/packages/lambda/src/cli/commands/quotas/list.tsindex 30ffff52a5..83ea2a3aeb 100644--- a/packages/lambda/src/cli/commands/quotas/list.ts+++ b/packages/lambda/src/cli/commands/quotas/list.ts@@ -21,25 +21,25 @@ export const quotasListCommand = async () => {Log.info();const [concurrencyLimit, defaultConcurrencyLimit, burstLimit, changes] =await Promise.all([- getServiceQuotasClient(region).send(+ getServiceQuotasClient(region, null).send(new GetServiceQuotaCommand({QuotaCode: LAMBDA_CONCURRENCY_LIMIT_QUOTA,ServiceCode: 'lambda',})),- getServiceQuotasClient(region).send(+ getServiceQuotasClient(region, null).send(new GetAWSDefaultServiceQuotaCommand({QuotaCode: LAMBDA_CONCURRENCY_LIMIT_QUOTA,ServiceCode: 'lambda',})),- getServiceQuotasClient(region).send(+ getServiceQuotasClient(region, null).send(new GetAWSDefaultServiceQuotaCommand({QuotaCode: LAMBDA_BURST_LIMIT_QUOTA,ServiceCode: 'lambda',})),- getServiceQuotasClient(region).send(+ getServiceQuotasClient(region, null).send(new ListRequestedServiceQuotaChangeHistoryByQuotaCommand({QuotaCode: LAMBDA_CONCURRENCY_LIMIT_QUOTA,ServiceCode: 'lambda',diff --git a/packages/lambda/src/functions/chunk-optimization/s3-optimization-file.ts b/packages/lambda/src/functions/chunk-optimization/s3-optimization-file.tsindex a459771ccc..24a2bfb433 100644--- a/packages/lambda/src/functions/chunk-optimization/s3-optimization-file.ts+++ b/packages/lambda/src/functions/chunk-optimization/s3-optimization-file.ts@@ -27,6 +27,7 @@ export const writeOptimization = async ({privacy: 'private',expectedBucketOwner,downloadBehavior: null,+ customCredentials: null,});};diff --git a/packages/lambda/src/functions/helpers/expected-out-name.ts b/packages/lambda/src/functions/helpers/expected-out-name.tsindex b44a0b1e81..c34cd06e08 100644--- a/packages/lambda/src/functions/helpers/expected-out-name.ts+++ b/packages/lambda/src/functions/helpers/expected-out-name.ts@@ -21,6 +21,7 @@ export const getExpectedOutName = (return {renderBucketName: bucketName,key: outStillName(renderMetadata.renderId, renderMetadata.imageFormat),+ customCredentials: null,};}@@ -34,6 +35,7 @@ export const getExpectedOutName = ('final')),+ customCredentials: null,};}diff --git a/packages/lambda/src/functions/helpers/find-output-file-in-bucket.ts b/packages/lambda/src/functions/helpers/find-output-file-in-bucket.tsindex fdaca17be9..06d0bfa871 100644--- a/packages/lambda/src/functions/helpers/find-output-file-in-bucket.ts+++ b/packages/lambda/src/functions/helpers/find-output-file-in-bucket.ts@@ -28,7 +28,7 @@ export const findOutputFileInBucket = async ({const expectedOutData = getExpectedOutName(renderMetadata, bucketName);try {- const head = await getS3Client(region).send(+ const head = await getS3Client(region, null).send(new HeadObjectCommand({Bucket: expectedOutData.renderBucketName,Key: expectedOutData.key,diff --git a/packages/lambda/src/functions/helpers/io.ts b/packages/lambda/src/functions/helpers/io.tsindex e8f0b815b1..b43fb58259 100644--- a/packages/lambda/src/functions/helpers/io.ts+++ b/packages/lambda/src/functions/helpers/io.ts@@ -9,6 +9,7 @@ import type {ReadStream} from 'fs';import mimeTypes from 'mime-types';import type {Readable} from 'stream';import type {AwsRegion} from '../../pricing/aws-regions';+import type {CustomCredentials} from '../../shared/aws-clients';import {getS3Client} from '../../shared/aws-clients';import type {Privacy} from '../../shared/constants';import type {DownloadBehavior} from '../../shared/content-disposition-header';@@ -31,7 +32,7 @@ export const lambdaLs = async ({continuationToken,}: LambdaLSInput): LambdaLsReturnType => {try {- const list = await getS3Client(region).send(+ const list = await getS3Client(region, null).send(new ListObjectsV2Command({Bucket: bucketName,Prefix: prefix,@@ -60,7 +61,7 @@ export const lambdaLs = async ({// Prevent from accessing a foreign bucket, retry without ExpectedBucketOwner and see if it works. If it works then it's an owner mismatch.if ((err as Error).stack?.includes('AccessDenied')) {- await getS3Client(region).send(+ await getS3Client(region, null).send(new ListObjectsV2Command({Bucket: bucketName,Prefix: prefix,@@ -84,7 +85,7 @@ export const lambdaDeleteFile = async ({bucketName: string;key: string;}) => {- await getS3Client(region).send(+ await getS3Client(region, null).send(new DeleteObjectCommand({Bucket: bucketName,Key: key,@@ -100,6 +101,7 @@ export const lambdaWriteFile = async ({privacy,expectedBucketOwner,downloadBehavior,+ customCredentials,}: {bucketName: string;key: string;@@ -108,8 +110,9 @@ export const lambdaWriteFile = async ({privacy: Privacy;expectedBucketOwner: string | null;downloadBehavior: DownloadBehavior | null;+ customCredentials: CustomCredentials | null;}): Promise<void> => {- await getS3Client(region).send(+ await getS3Client(region, customCredentials).send(new PutObjectCommand({Bucket: bucketName,Key: key,@@ -138,7 +141,7 @@ export const lambdaReadFile = async ({region: AwsRegion;expectedBucketOwner: string;}): Promise<Readable> => {- const {Body} = await getS3Client(region).send(+ const {Body} = await getS3Client(region, null).send(new GetObjectCommand({Bucket: bucketName,Key: key,diff --git a/packages/lambda/src/functions/helpers/read-with-progress.ts b/packages/lambda/src/functions/helpers/read-with-progress.tsindex 096013a18c..90ea042f2d 100644--- a/packages/lambda/src/functions/helpers/read-with-progress.ts+++ b/packages/lambda/src/functions/helpers/read-with-progress.ts@@ -25,7 +25,7 @@ export const lambdaDownloadFileWithProgress = async ({outputPath: string;onProgress: LambdaReadFileProgress;}): Promise<{sizeInBytes: number; to: string}> => {- const client = getS3Client(region);+ const client = getS3Client(region, null);const command = new GetObjectCommand({Bucket: bucketName,ExpectedBucketOwner: expectedBucketOwner,diff --git a/packages/lambda/src/functions/helpers/write-lambda-error.ts b/packages/lambda/src/functions/helpers/write-lambda-error.tsindex 5ac4b629b4..ada608e4ad 100644--- a/packages/lambda/src/functions/helpers/write-lambda-error.ts+++ b/packages/lambda/src/functions/helpers/write-lambda-error.ts@@ -65,5 +65,6 @@ export const writeLambdaError = async ({privacy: 'private',expectedBucketOwner,downloadBehavior: null,+ customCredentials: null,});};diff --git a/packages/lambda/src/functions/helpers/write-post-render-data.ts b/packages/lambda/src/functions/helpers/write-post-render-data.tsindex 545d6be48e..001a304f28 100644--- a/packages/lambda/src/functions/helpers/write-post-render-data.ts+++ b/packages/lambda/src/functions/helpers/write-post-render-data.ts@@ -24,5 +24,6 @@ export const writePostRenderData = async ({expectedBucketOwner,region,downloadBehavior: null,+ customCredentials: null,});};diff --git a/packages/lambda/src/functions/launch.ts b/packages/lambda/src/functions/launch.tsindex 345ae31fe8..0b4f9e96b0 100644--- a/packages/lambda/src/functions/launch.ts+++ b/packages/lambda/src/functions/launch.ts@@ -250,6 +250,7 @@ const innerLaunchHandler = async (params: LambdaPayload, options: Options) => {privacy: 'private',expectedBucketOwner: options.expectedBucketOwner,downloadBehavior: null,+ customCredentials: null,});await Promise.all(@@ -294,6 +295,7 @@ const innerLaunchHandler = async (params: LambdaPayload, options: Options) => {privacy: 'private',expectedBucketOwner: options.expectedBucketOwner,downloadBehavior: null,+ customCredentials: null,}).catch((err) => {writeLambdaError({bucketName: params.bucketName,@@ -336,7 +338,7 @@ const innerLaunchHandler = async (params: LambdaPayload, options: Options) => {encodingStop = Date.now();}- const {key, renderBucketName} = getExpectedOutName(+ const {key, renderBucketName, customCredentials} = getExpectedOutName(renderMetadata,params.bucketName);@@ -351,6 +353,7 @@ const innerLaunchHandler = async (params: LambdaPayload, options: Options) => {privacy: params.privacy,expectedBucketOwner: options.expectedBucketOwner,downloadBehavior: params.downloadBehavior,+ customCredentials,});let chunkProm: Promise<unknown> = Promise.resolve();@@ -420,6 +423,7 @@ const innerLaunchHandler = async (params: LambdaPayload, options: Options) => {privacy: 'private',expectedBucketOwner: options.expectedBucketOwner,downloadBehavior: null,+ customCredentials: null,});const errorExplanationsProm = inspectErrors({diff --git a/packages/lambda/src/functions/renderer.ts b/packages/lambda/src/functions/renderer.tsindex 631c1cb0e8..3b8a0a3442 100644--- a/packages/lambda/src/functions/renderer.ts+++ b/packages/lambda/src/functions/renderer.ts@@ -134,6 +134,7 @@ const renderHandler = async (region: getCurrentRegionInFunction(),expectedBucketOwner: options.expectedBucketOwner,downloadBehavior: null,+ customCredentials: null,}).catch((err) => reject(err));},puppeteerInstance: browserInstance,@@ -221,6 +222,7 @@ const renderHandler = async (privacy: params.privacy,expectedBucketOwner: options.expectedBucketOwner,downloadBehavior: null,+ customCredentials: null,});await Promise.all([fs.promises.rm(outputLocation, {recursive: true}),@@ -238,6 +240,7 @@ const renderHandler = async (privacy: 'private',expectedBucketOwner: options.expectedBucketOwner,downloadBehavior: null,+ customCredentials: null,}),]);};diff --git a/packages/lambda/src/functions/start.ts b/packages/lambda/src/functions/start.tsindex 18fd82530f..4c5255c717 100644--- a/packages/lambda/src/functions/start.ts+++ b/packages/lambda/src/functions/start.ts@@ -43,6 +43,7 @@ export const startHandler = async (params: LambdaPayload, options: Options) => {expectedBucketOwner: options.expectedBucketOwner,key: initalizedMetadataKey(renderId),privacy: 'private',+ customCredentials: null,});const payload: LambdaPayload = {diff --git a/packages/lambda/src/functions/still.ts b/packages/lambda/src/functions/still.tsindex 9e258dde02..e2d266d9ae 100644--- a/packages/lambda/src/functions/still.ts+++ b/packages/lambda/src/functions/still.ts@@ -124,6 +124,7 @@ const innerStillHandler = async (privacy: 'private',expectedBucketOwner: options.expectedBucketOwner,downloadBehavior: null,+ customCredentials: null,});await renderStill({@@ -144,7 +145,7 @@ const innerStillHandler = async (downloadMap,});- const {key, renderBucketName} = getExpectedOutName(+ const {key, renderBucketName, customCredentials} = getExpectedOutName(renderMetadata,bucketName);@@ -159,6 +160,7 @@ const innerStillHandler = async (expectedBucketOwner: options.expectedBucketOwner,region: getCurrentRegionInFunction(),downloadBehavior: lambdaParams.downloadBehavior,+ customCredentials,});await fs.promises.rm(outputPath, {recursive: true});diff --git a/packages/lambda/src/shared/aws-clients.ts b/packages/lambda/src/shared/aws-clients.tsindex 83e7f7d1eb..26d4753300 100644--- a/packages/lambda/src/shared/aws-clients.ts+++ b/packages/lambda/src/shared/aws-clients.ts@@ -61,10 +61,21 @@ export type ServiceMapping = {servicequotas: ServiceQuotasClient;};-export const getServiceClient = <T extends keyof ServiceMapping>(- region: AwsRegion,- service: T-): ServiceMapping[T] => {+export type CustomCredentials = {+ accessKeyId: string;+ secretAccessKey: string;+ endpoint: string;+};++export const getServiceClient = <T extends keyof ServiceMapping>({+ region,+ service,+ customCredentials,+}: {+ region: AwsRegion;+ service: T;+ customCredentials: CustomCredentials | null;+}): ServiceMapping[T] => {if (!_clients[region]) {_clients[region] = {};}@@ -102,11 +113,23 @@ export const getServiceClient = <T extends keyof ServiceMapping>(if (!_clients[region][key][service]) {checkCredentials();- // @ts-expect-error- _clients[region][key][service] = new Client({- region,- credentials: getCredentials(),- });+ if (customCredentials) {+ // @ts-expect-error+ _clients[region][key][service] = new Client({+ region,+ credentials: {+ accessKeyId: customCredentials.accessKeyId,+ secretAccessKey: customCredentials.secretAccessKey,+ },+ endpoint: customCredentials.endpoint,+ });+ } else {+ // @ts-expect-error+ _clients[region][key][service] = new Client({+ region,+ credentials: getCredentials(),+ });+ }}// @ts-expect-error@@ -116,23 +139,39 @@ export const getServiceClient = <T extends keyof ServiceMapping>(export const getCloudWatchLogsClient = (region: AwsRegion): CloudWatchLogsClient => {- return getServiceClient(region, 'cloudwatch');+ return getServiceClient({+ region,+ service: 'cloudwatch',+ customCredentials: null,+ });};-export const getS3Client = (region: AwsRegion): S3Client => {- return getServiceClient(region, 's3');+export const getS3Client = (+ region: AwsRegion,+ customCredentials: CustomCredentials | null+): S3Client => {+ return getServiceClient({region, service: 's3', customCredentials});};export const getLambdaClient = (region: AwsRegion): LambdaClient => {- return getServiceClient(region, 'lambda');+ return getServiceClient({+ region,+ service: 'lambda',+ customCredentials: null,+ });};export const getIamClient = (region: AwsRegion): IAMClient => {- return getServiceClient(region, 'iam');+ return getServiceClient({region, service: 'iam', customCredentials: null});};export const getServiceQuotasClient = (- region: AwsRegion+ region: AwsRegion,+ customCredentials: CustomCredentials | null): ServiceQuotasClient => {- return getServiceClient(region, 'servicequotas');+ return getServiceClient({+ region,+ service: 'servicequotas',+ customCredentials,+ });};diff --git a/packages/lambda/src/shared/constants.ts b/packages/lambda/src/shared/constants.tsindex 92b4534c44..96a7a70ecf 100644--- a/packages/lambda/src/shared/constants.ts+++ b/packages/lambda/src/shared/constants.ts@@ -11,6 +11,7 @@ import type {VideoConfig} from 'remotion';import type {ChunkRetry} from '../functions/helpers/get-retry-stats';import type {EnhancedErrorInfo} from '../functions/helpers/write-lambda-error';import type {AwsRegion} from '../pricing/aws-regions';+import type {CustomCredentials} from './aws-clients';import type {DownloadBehavior} from './content-disposition-header';import type {ExpensiveChunk} from './get-most-expensive-chunks';import type {LambdaArchitecture} from './validate-architecture';@@ -128,11 +129,13 @@ export type OutNameInput =| {bucketName: string;key: string;+ customS3Implementation?: CustomCredentials;};export type OutNameOutput = {renderBucketName: string;key: string;+ customCredentials: CustomCredentials | null;};export const optimizationProfile = (siteId: string, compositionId: string) =>@@ -151,10 +154,15 @@ export const customOutName = (return {renderBucketName: bucketName,key: `${rendersPrefix(renderId)}/${name}`,+ customCredentials: null,};}- return {key: name.key, renderBucketName: name.bucketName};+ return {+ key: name.key,+ renderBucketName: name.bucketName,+ customCredentials: name.customS3Implementation ?? null,+ };};export const postRenderDataKey = (renderId: string) => {