Skip to content

🎥 Make videos programmatically with React

more reshuffling for tests

Jonny Burgerc7bc53959cd3
diff --git a/packages/lambda/src/api/__mocks__/mock-s3.ts b/packages/lambda/src/api/__mocks__/mock-s3.ts
deleted file mode 100644
index 2a8d0c9438..0000000000
--- a/packages/lambda/src/api/__mocks__/mock-s3.ts
+++ /dev/null
@@ -1,88 +0,0 @@
-import type {Privacy} from '@remotion/serverless/client';
-import type {ReadStream} from 'node:fs';
-import type {AwsRegion} from '../../regions';
-
-type S3MockFile = {
- bucketName: string;
- region: AwsRegion;
- acl: 'public-read' | 'private' | 'none';
- key: string;
- content: string | ReadStream;
-};
-
-let mockS3Store: S3MockFile[] = [];
-
-export const writeMockS3File = ({
- body,
- privacy,
- bucketName,
- key,
- region,
-}: {
- body: string | ReadStream;
- privacy: Privacy;
- bucketName: string;
- key: string;
- region: AwsRegion;
-}) => {
- mockS3Store = mockS3Store.filter((m) => {
- return !(
- m.region === region &&
- m.bucketName === bucketName &&
- m.key === key
- );
- });
- mockS3Store.push({
- content: body,
- acl:
- privacy === 'no-acl'
- ? 'none'
- : privacy === 'public'
- ? 'public-read'
- : 'private',
- bucketName,
- key,
- region,
- });
-};
-
-export const readMockS3File = ({
- region,
- key,
- bucketName,
-}: {
- region: AwsRegion;
- key: string;
- bucketName: string;
-}) => {
- return mockS3Store.find(
- (s) => s.key === key && s.region === region && s.bucketName === bucketName,
- );
-};
-
-export const getS3FilesInBucket = ({
- bucketName,
- region,
-}: {
- bucketName: string;
- region: string;
-}) => {
- return mockS3Store.filter(
- (s) => s.bucketName === bucketName && s.region === region,
- );
-};
-
-export const mockDeleteS3File = ({
- key,
- region,
- bucketName,
-}: {
- key: string;
- region: AwsRegion;
- bucketName: string;
-}) => {
- mockS3Store = mockS3Store.filter(
- (s) =>
- !(s.bucketName === bucketName && s.key === key && s.region === region),
- );
-};
diff --git a/packages/lambda/src/api/__mocks__/upload-dir.ts b/packages/lambda/src/api/__mocks__/upload-dir.ts
index f165314e48..62071026d0 100644
--- a/packages/lambda/src/api/__mocks__/upload-dir.ts
+++ b/packages/lambda/src/api/__mocks__/upload-dir.ts
@@ -1,5 +1,5 @@
+import {writeMockS3File} from '../../test/mocks/mock-store';
import type {MockFile, uploadDir as original} from '../upload-dir';
-import {writeMockS3File} from './mock-s3';
export const getDirFiles = (dir: string): MockFile[] => {
if (dir === '/path/to/bundle-1') {
diff --git a/packages/lambda/src/api/bucket-exists.ts b/packages/lambda/src/api/bucket-exists.ts
index d326466fd1..68df0b7f0b 100644
--- a/packages/lambda/src/api/bucket-exists.ts
+++ b/packages/lambda/src/api/bucket-exists.ts
@@ -1,6 +1,6 @@
import {GetBucketLocationCommand} from '@aws-sdk/client-s3';
import type {AwsRegion} from '../regions';
-import {getS3Client} from '../shared/aws-clients';
+import {getS3Client} from '../shared/get-s3-client';
export const bucketExistsInRegion = async ({
bucketName,
diff --git a/packages/lambda/src/api/clean-items.ts b/packages/lambda/src/api/clean-items.ts
index ed4a0a9fe7..c04955b3db 100644
--- a/packages/lambda/src/api/clean-items.ts
+++ b/packages/lambda/src/api/clean-items.ts
@@ -1,6 +1,6 @@
import {DeleteObjectCommand} from '@aws-sdk/client-s3';
import type {AwsRegion} from '../regions';
-import {getS3Client} from '../shared/aws-clients';
+import {getS3Client} from '../shared/get-s3-client';
import {pLimit} from '../shared/p-limit';
const limit = pLimit(10);
diff --git a/packages/lambda/src/api/create-bucket.ts b/packages/lambda/src/api/create-bucket.ts
index d7fc6a70c4..56cc2a2fbe 100644
--- a/packages/lambda/src/api/create-bucket.ts
+++ b/packages/lambda/src/api/create-bucket.ts
@@ -6,7 +6,7 @@ import {
} from '@aws-sdk/client-s3';
import type {ProviderSpecifics} from '@remotion/serverless';
import type {AwsRegion} from '../regions';
-import {getS3Client} from '../shared/aws-clients';
+import {getS3Client} from '../shared/get-s3-client';
export const createBucket: ProviderSpecifics<AwsRegion>['createBucket'] =
async ({region, bucketName}) => {
diff --git a/packages/lambda/src/api/delete-render.ts b/packages/lambda/src/api/delete-render.ts
index 6f90e0f4c4..e52cd55b46 100644
--- a/packages/lambda/src/api/delete-render.ts
+++ b/packages/lambda/src/api/delete-render.ts
@@ -1,8 +1,9 @@
import type {CustomCredentials} from '@remotion/serverless/client';
import {rendersPrefix} from '../defaults';
+import {awsImplementation} from '../functions/aws-implementation';
import {getExpectedOutName} from '../functions/helpers/expected-out-name';
import {getOverallProgressS3} from '../functions/helpers/get-overall-progress-s3';
-import {lambdaDeleteFile, lambdaLs} from '../functions/helpers/io';
+import {lambdaDeleteFile} from '../functions/helpers/io';
import type {AwsRegion} from '../regions';
import {getAccountId} from '../shared/get-account-id';
import {cleanItems} from './clean-items';
@@ -51,7 +52,7 @@ export const deleteRender = async (input: DeleteRenderInput) => {
region: input.region,
});
- let files = await lambdaLs({
+ let files = await awsImplementation.listObjects({
bucketName: input.bucketName,
prefix: rendersPrefix(input.renderId),
region: input.region,
@@ -71,7 +72,7 @@ export const deleteRender = async (input: DeleteRenderInput) => {
onBeforeItemDeleted: () => undefined,
region: input.region,
});
- files = await lambdaLs({
+ files = await awsImplementation.listObjects({
bucketName: input.bucketName,
prefix: rendersPrefix(input.renderId),
region: input.region,
diff --git a/packages/lambda/src/api/delete-site.ts b/packages/lambda/src/api/delete-site.ts
index f4027210d1..ff921bfb9d 100644
--- a/packages/lambda/src/api/delete-site.ts
+++ b/packages/lambda/src/api/delete-site.ts
@@ -1,5 +1,5 @@
import {getSitesKey} from '../defaults';
-import {lambdaLs} from '../functions/helpers/io';
+import {awsImplementation} from '../functions/aws-implementation';
import type {AwsRegion} from '../regions';
import {getAccountId} from '../shared/get-account-id';
import {cleanItems} from './clean-items';
@@ -33,7 +33,7 @@ export const deleteSite = async ({
}: DeleteSiteInput): Promise<DeleteSiteOutput> => {
const accountId = await getAccountId({region});
- let files = await lambdaLs({
+ let files = await awsImplementation.listObjects({
bucketName,
// The `/` is important to not accidentially delete sites with the same name but containing a suffix.
prefix: `${getSitesKey(siteName)}/`,
@@ -54,7 +54,7 @@ export const deleteSite = async ({
onBeforeItemDeleted: () => undefined,
region,
});
- files = await lambdaLs({
+ files = await awsImplementation.listObjects({
bucketName,
// The `/` is important to not accidentially delete sites with the same name but containing a suffix.
prefix: `${getSitesKey(siteName)}/`,
diff --git a/packages/lambda/src/api/deploy-site.ts b/packages/lambda/src/api/deploy-site.ts
index 97b82fbe7b..2ada067e85 100644
--- a/packages/lambda/src/api/deploy-site.ts
+++ b/packages/lambda/src/api/deploy-site.ts
@@ -2,8 +2,10 @@ import {type GitSource, type WebpackOverrideFn} from '@remotion/bundler';
import type {ToOptions} from '@remotion/renderer';
import type {BrowserSafeApis} from '@remotion/renderer/client';
import {NoReactAPIs} from '@remotion/renderer/pure';
+import type {ProviderSpecifics} from '@remotion/serverless';
import fs from 'node:fs';
-import {lambdaDeleteFile, lambdaLs} from '../functions/helpers/io';
+import {awsImplementation} from '../functions/aws-implementation';
+import {lambdaDeleteFile} from '../functions/helpers/io';
import type {AwsRegion} from '../regions';
import {bundleSite} from '../shared/bundle-site';
import {getSitesKey} from '../shared/constants';
@@ -63,7 +65,10 @@ const mandatoryDeploySite = async ({
privacy,
gitSource,
throwIfSiteExists,
-}: MandatoryParameters & OptionalParameters): DeploySiteOutput => {
+}: MandatoryParameters &
+ OptionalParameters & {
+ providerSpecifics: ProviderSpecifics<AwsRegion>;
+ }): DeploySiteOutput => {
validateAwsRegion(region);
validateBucketName(bucketName, {
mustStartWithRemotion: !options?.bypassBucketNameValidation,
@@ -86,7 +91,7 @@ const mandatoryDeploySite = async ({
const subFolder = getSitesKey(siteName);
const [files, bundled] = await Promise.all([
- lambdaLs({
+ awsImplementation.listObjects({
bucketName,
expectedBucketOwner: accountId,
region,
@@ -191,5 +196,6 @@ export const deploySite = (args: DeploySiteInput) => {
indent: false,
logLevel: 'info',
throwIfSiteExists: args.throwIfSiteExists ?? false,
+ providerSpecifics: awsImplementation,
});
};
diff --git a/packages/lambda/src/api/get-buckets.ts b/packages/lambda/src/api/get-buckets.ts
index 932fbea622..9959479a13 100644
--- a/packages/lambda/src/api/get-buckets.ts
+++ b/packages/lambda/src/api/get-buckets.ts
@@ -2,7 +2,7 @@ import {GetBucketLocationCommand, ListBucketsCommand} from '@aws-sdk/client-s3';
import type {ProviderSpecifics} from '@remotion/serverless';
import {REMOTION_BUCKET_PREFIX} from '../defaults';
import type {AwsRegion} from '../regions';
-import {getS3Client} from '../shared/aws-clients';
+import {getS3Client} from '../shared/get-s3-client';
import {parseBucketName} from '../shared/validate-bucketname';
export type BucketWithLocation = {
diff --git a/packages/lambda/src/api/get-sites.ts b/packages/lambda/src/api/get-sites.ts
index 7d56b825bb..44a822cda0 100644
--- a/packages/lambda/src/api/get-sites.ts
+++ b/packages/lambda/src/api/get-sites.ts
@@ -1,6 +1,5 @@
import type {ProviderSpecifics} from '@remotion/serverless';
import {awsImplementation} from '../functions/aws-implementation';
-import {lambdaLs} from '../functions/helpers/io';
import type {AwsRegion} from '../regions';
import {getSitesKey} from '../shared/constants';
import {getAccountId} from '../shared/get-account-id';
@@ -40,7 +39,7 @@ export const internalGetSites = async ({
const sites: {[key: string]: Site} = {};
for (const bucket of remotionBuckets) {
- const ls = await lambdaLs({
+ const ls = await providerSpecifics.listObjects({
bucketName: bucket.name,
prefix: getSitesKey(''),
region,
diff --git a/packages/lambda/src/api/presign-url.ts b/packages/lambda/src/api/presign-url.ts
index 43ba214762..8aee0aee70 100644
--- a/packages/lambda/src/api/presign-url.ts
+++ b/packages/lambda/src/api/presign-url.ts
@@ -1,7 +1,7 @@
import {GetObjectCommand, HeadObjectCommand} from '@aws-sdk/client-s3';
import {getSignedUrl} from '@aws-sdk/s3-request-presigner';
import type {AwsRegion} from '../regions';
-import {getS3Client} from '../shared/aws-clients';
+import {getS3Client} from '../shared/get-s3-client';
import {validateBucketName} from '../shared/validate-bucketname';
import {validatePresignExpiration} from '../shared/validate-presign-expiration';
diff --git a/packages/lambda/src/api/upload-dir.ts b/packages/lambda/src/api/upload-dir.ts
index 0817314c88..a3bc06b244 100644
--- a/packages/lambda/src/api/upload-dir.ts
+++ b/packages/lambda/src/api/upload-dir.ts
@@ -5,7 +5,7 @@ import type {Dirent} from 'node:fs';
import {createReadStream, promises as fs} from 'node:fs';
import path from 'node:path';
import type {AwsRegion} from '../regions';
-import {getS3Client} from '../shared/aws-clients';
+import {getS3Client} from '../shared/get-s3-client';
import {makeS3Key} from '../shared/make-s3-key';
import {pLimit} from '../shared/p-limit';
diff --git a/packages/lambda/src/cli/commands/sites/create.ts b/packages/lambda/src/cli/commands/sites/create.ts
index 33335abbe7..dda51f450a 100644
--- a/packages/lambda/src/cli/commands/sites/create.ts
+++ b/packages/lambda/src/cli/commands/sites/create.ts
@@ -189,6 +189,7 @@ export const sitesCreateSubcommand = async (
indent: false,
logLevel,
throwIfSiteExists,
+ providerSpecifics: implementation,
});
const uploadDuration = Date.now() - uploadStart;
diff --git a/packages/lambda/src/functions/aws-implementation.ts b/packages/lambda/src/functions/aws-implementation.ts
index 97ed34e73d..de67e5d9eb 100644
--- a/packages/lambda/src/functions/aws-implementation.ts
+++ b/packages/lambda/src/functions/aws-implementation.ts
@@ -1,6 +1,7 @@
import type {ProviderSpecifics} from '@remotion/serverless';
import {createBucket} from '../api/create-bucket';
import {getRemotionBuckets} from '../api/get-buckets';
+import {lambdaLsImplementation} from '../io/list-objects';
import type {AwsRegion} from '../regions';
import {applyLifeCyleOperation} from '../shared/lifecycle-rules';
import {getCurrentRegionInFunctionImplementation} from './helpers/get-current-region';
@@ -26,4 +27,5 @@ export const awsImplementation: ProviderSpecifics<AwsRegion> = {
getBuckets: getRemotionBuckets,
createBucket,
applyLifeCycle: applyLifeCyleOperation,
+ listObjects: lambdaLsImplementation,
};
diff --git a/packages/lambda/src/functions/helpers/__mocks__/io.ts b/packages/lambda/src/functions/helpers/__mocks__/io.ts
index 1f543ceab6..f336dcbf84 100644
--- a/packages/lambda/src/functions/helpers/__mocks__/io.ts
+++ b/packages/lambda/src/functions/helpers/__mocks__/io.ts
@@ -1,19 +1,16 @@
-import type {_Object} from '@aws-sdk/client-s3';
import {Readable} from 'stream';
-import {
- getS3FilesInBucket,
- mockDeleteS3File,
- readMockS3File,
- writeMockS3File,
-} from '../../../api/__mocks__/mock-s3';
+
import type {
lambdaDeleteFile as deleteOriginal,
lambdaHeadCommand as headOriginal,
- lambdaLs as lsOriginal,
lambdaReadFile as readOriginal,
lambdaWriteFile as writeOriginal,
} from '../../../functions/helpers/io';
-import type {LambdaLSInput, LambdaLsReturnType} from '../io';
+import {
+ mockDeleteS3File,
+ readMockS3File,
+ writeMockS3File,
+} from '../../../test/mocks/mock-store';
export const lambdaReadFile: typeof readOriginal = ({
bucketName,
@@ -83,32 +80,3 @@ export const lambdaHeadCommand: typeof headOriginal = ({
LastModified: new Date(),
});
};
-
-export const lambdaLs: typeof lsOriginal = (
- input: LambdaLSInput,
-): LambdaLsReturnType => {
- if (!input) {
- throw new Error('need to pass input');
- }
-
- const files = getS3FilesInBucket({
- bucketName: input.bucketName,
- region: input.region,
- });
-
- return Promise.resolve(
- files
- .filter((p) => p.key.startsWith(input.prefix))
- .map((file): _Object => {
- const size = typeof file.content === 'string' ? file.content.length : 0;
- return {
- Key: file.key,
- ETag: 'etag',
- LastModified: new Date(0),
- Owner: undefined,
- Size: size,
- StorageClass: undefined,
- };
- }),
- );
-};
diff --git a/packages/lambda/src/functions/helpers/io.ts b/packages/lambda/src/functions/helpers/io.ts
index dcf6ee9010..fcf3221d1f 100644
--- a/packages/lambda/src/functions/helpers/io.ts
+++ b/packages/lambda/src/functions/helpers/io.ts
@@ -3,7 +3,6 @@ import {
DeleteObjectCommand,
GetObjectCommand,
HeadObjectCommand,
- ListObjectsV2Command,
PutObjectCommand,
} from '@aws-sdk/client-s3';
import type {
@@ -15,8 +14,8 @@ import mimeTypes from 'mime-types';
import type {ReadStream} from 'node:fs';
import type {Readable} from 'stream';
import type {AwsRegion} from '../../regions';
-import {getS3Client} from '../../shared/aws-clients';
import {getContentDispositionHeader} from '../../shared/content-disposition-header';
+import {getS3Client} from '../../shared/get-s3-client';
export type LambdaLSInput = {
bucketName: string;
@@ -27,58 +26,6 @@ export type LambdaLSInput = {
};
export type LambdaLsReturnType = Promise<_Object[]>;
-export const lambdaLs = async ({
- bucketName,
- prefix,
- region,
- expectedBucketOwner,
- continuationToken,
-}: LambdaLSInput): LambdaLsReturnType => {
- try {
- const list = await getS3Client(region, null).send(
- new ListObjectsV2Command({
- Bucket: bucketName,
- Prefix: prefix,
- ExpectedBucketOwner: expectedBucketOwner ?? undefined,
- ContinuationToken: continuationToken,
- }),
- );
- if (list.NextContinuationToken) {
- return [
- ...(list.Contents ?? []),
- ...(await lambdaLs({
- bucketName,
- prefix,
- expectedBucketOwner,
- region,
- continuationToken: list.NextContinuationToken,
- })),
- ];
- }
-
- return list.Contents ?? [];
- } catch (err) {
- if (!expectedBucketOwner) {
- throw err;
- }
-
- // 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, null).send(
- new ListObjectsV2Command({
- Bucket: bucketName,
- Prefix: prefix,
- }),
- );
- throw new Error(
- `Bucket owner mismatch: Expected the bucket ${bucketName} to be owned by you (AWS Account ID: ${expectedBucketOwner}) but it's not the case. Did you accidentially specify the wrong bucket?`,
- );
- }
-
- throw err;
- }
-};
-
export const lambdaDeleteFile = async ({
bucketName,
key,
diff --git a/packages/lambda/src/functions/helpers/read-with-progress.ts b/packages/lambda/src/functions/helpers/read-with-progress.ts
index 2ca4dd4b75..af5f8543d1 100644
--- a/packages/lambda/src/functions/helpers/read-with-progress.ts
+++ b/packages/lambda/src/functions/helpers/read-with-progress.ts
@@ -4,7 +4,7 @@ import type {LogLevel} from '@remotion/renderer';
import {RenderInternals} from '@remotion/renderer';
import type {CustomCredentials} from '@remotion/serverless/client';
import type {AwsRegion} from '../../regions';
-import {getS3Client} from '../../shared/aws-clients';
+import {getS3Client} from '../../shared/get-s3-client';
export type LambdaReadFileProgress = (progress: {
totalSize: number;
diff --git a/packages/lambda/src/io/list-objects.ts b/packages/lambda/src/io/list-objects.ts
new file mode 100644
index 0000000000..6c350695c7
--- /dev/null
+++ b/packages/lambda/src/io/list-objects.ts
@@ -0,0 +1,73 @@
+import {ListObjectsV2Command} from '@aws-sdk/client-s3';
+import type {ProviderSpecifics} from '@remotion/serverless';
+import type {AwsRegion} from '../regions';
+import {getS3Client} from '../shared/get-s3-client';
+
+export const lambdaLsImplementation: ProviderSpecifics<AwsRegion>['listObjects'] =
+ async ({
+ bucketName,
+ prefix,
+ region,
+ expectedBucketOwner,
+ continuationToken,
+ }) => {
+ try {
+ const list = await getS3Client(region, null).send(
+ new ListObjectsV2Command({
+ Bucket: bucketName,
+ Prefix: prefix,
+ ExpectedBucketOwner: expectedBucketOwner ?? undefined,
+ ContinuationToken: continuationToken,
+ }),
+ );
+ if (list.NextContinuationToken) {
+ return [
+ ...(list.Contents ?? []).map((o) => {
+ return {
+ Key: o.Key as string,
+ LastModified: o.LastModified as Date,
+ ETag: o.ETag as string,
+ Size: o.Size as number,
+ };
+ }),
+ ...(await lambdaLsImplementation({
+ bucketName,
+ prefix,
+ expectedBucketOwner,
+ region,
+ continuationToken: list.NextContinuationToken,
+ })),
+ ];
+ }
+
+ return (
+ (list.Contents || [])?.map((o) => {
+ return {
+ Key: o.Key as string,
+ LastModified: o.LastModified as Date,
+ ETag: o.ETag as string,
+ Size: o.Size as number,
+ };
+ }) ?? []
+ );
+ } catch (err) {
+ if (!expectedBucketOwner) {
+ throw err;
+ }
+
+ // 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, null).send(
+ new ListObjectsV2Command({
+ Bucket: bucketName,
+ Prefix: prefix,
+ }),
+ );
+ throw new Error(
+ `Bucket owner mismatch: Expected the bucket ${bucketName} to be owned by you (AWS Account ID: ${expectedBucketOwner}) but it's not the case. Did you accidentially specify the wrong bucket?`,
+ );
+ }
+
+ throw err;
+ }
+ };
diff --git a/packages/lambda/src/shared/aws-clients.ts b/packages/lambda/src/shared/aws-clients.ts
index b7b214dac5..a98a8c4afa 100644
--- a/packages/lambda/src/shared/aws-clients.ts
+++ b/packages/lambda/src/shared/aws-clients.ts
@@ -1,245 +1,10 @@
-import {CloudWatchLogsClient} from '@aws-sdk/client-cloudwatch-logs';
-import {IAMClient} from '@aws-sdk/client-iam';
-import {LambdaClient} from '@aws-sdk/client-lambda';
-import {S3Client} from '@aws-sdk/client-s3';
-import {ServiceQuotasClient} from '@aws-sdk/client-service-quotas';
-import {STSClient} from '@aws-sdk/client-sts';
-import {fromIni} from '@aws-sdk/credential-providers';
-import type {CustomCredentials} from '@remotion/serverless/client';
-import {random} from 'remotion/no-react';
+import type {CloudWatchLogsClient} from '@aws-sdk/client-cloudwatch-logs';
+import type {IAMClient} from '@aws-sdk/client-iam';
+import type {LambdaClient} from '@aws-sdk/client-lambda';
+import type {ServiceQuotasClient} from '@aws-sdk/client-service-quotas';
+import type {STSClient} from '@aws-sdk/client-sts';
import type {AwsRegion} from '../regions';
-import {checkCredentials} from './check-credentials';
-import {MAX_FUNCTIONS_PER_RENDER} from './constants';
-import {isInsideLambda} from './is-in-lambda';
-
-const _clients: Partial<
- Record<
- string,
- | CloudWatchLogsClient
- | LambdaClient
- | S3Client
- | IAMClient
- | ServiceQuotasClient
- | STSClient
- >
-> = {};
-
-type CredentialPair = {
- accessKeyId: string;
- secretAccessKey: string;
- sessionToken?: string;
-};
-type AwsCredentialIdentityProvider = ReturnType<typeof fromIni>;
-
-const getCredentials = ():
- | CredentialPair
- | AwsCredentialIdentityProvider
- | undefined => {
- if (isInsideLambda()) {
- return undefined;
- }
-
- if (process.env.REMOTION_AWS_PROFILE) {
- return fromIni({
- profile: process.env.REMOTION_AWS_PROFILE,
- });
- }
-
- if (
- process.env.REMOTION_AWS_ACCESS_KEY_ID &&
- process.env.REMOTION_AWS_SECRET_ACCESS_KEY &&
- process.env.REMOTION_AWS_SESSION_TOKEN
- ) {
- return {
- accessKeyId: process.env.REMOTION_AWS_ACCESS_KEY_ID,
- secretAccessKey: process.env.REMOTION_AWS_SECRET_ACCESS_KEY,
- sessionToken: process.env.REMOTION_AWS_SESSION_TOKEN,
- };
- }
-
- if (
- process.env.REMOTION_AWS_ACCESS_KEY_ID &&
- process.env.REMOTION_AWS_SECRET_ACCESS_KEY
- ) {
- return {
- accessKeyId: process.env.REMOTION_AWS_ACCESS_KEY_ID,
- secretAccessKey: process.env.REMOTION_AWS_SECRET_ACCESS_KEY,
- };
- }
-
- if (process.env.AWS_PROFILE) {
- return fromIni({
- profile: process.env.AWS_PROFILE,
- });
- }
-
- if (
- process.env.AWS_ACCESS_KEY_ID &&
- process.env.AWS_SECRET_ACCESS_KEY &&
- process.env.AWS_SESSION_TOKEN
- ) {
- return {
- accessKeyId: process.env.AWS_ACCESS_KEY_ID as string,
- secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY as string,
- sessionToken: process.env.AWS_SESSION_TOKEN as string,
- };
- }
-
- if (process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY) {
- return {
- accessKeyId: process.env.AWS_ACCESS_KEY_ID as string,
- secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY as string,
- };
- }
-
- return undefined;
-};
-
-const getCredentialsHash = ({
- customCredentials,
- region,
- service,
-}: {
- region: AwsRegion;
- customCredentials: CustomCredentials<AwsRegion> | null;
- service: keyof ServiceMapping;
-}): string => {
- const hashComponents: {[key: string]: unknown} = {};
-
- if (process.env.REMOTION_SKIP_AWS_CREDENTIALS_CHECK) {
- hashComponents.credentials = {
- credentialsSkipped: true,
- };
- } else if (process.env.REMOTION_AWS_PROFILE) {
- hashComponents.credentials = {
- awsProfile: process.env.REMOTION_AWS_PROFILE,
- };
- } else if (
- process.env.REMOTION_AWS_ACCESS_KEY_ID &&
- process.env.REMOTION_AWS_SECRET_ACCESS_KEY
- ) {
- hashComponents.credentials = {
- accessKeyId: process.env.REMOTION_AWS_ACCESS_KEY_ID,
- secretAccessKey: process.env.REMOTION_AWS_SECRET_ACCESS_KEY,
- };
- } else if (process.env.AWS_PROFILE) {
- hashComponents.credentials = {
- awsProfile: process.env.AWS_PROFILE,
- };
- } else if (
- process.env.AWS_ACCESS_KEY_ID &&
- process.env.AWS_SECRET_ACCESS_KEY
- ) {
- hashComponents.credentials = {
- accessKeyId: process.env.AWS_ACCESS_KEY_ID as string,
- secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY as string,
- };
- }
-
- hashComponents.customCredentials = customCredentials;
- hashComponents.region = region;
- hashComponents.service = service;
-
- return random(JSON.stringify(hashComponents)).toString().replace('0.', '');
-};
-
-export type ServiceMapping = {
- s3: S3Client;
- cloudwatch: CloudWatchLogsClient;
- iam: IAMClient;
- lambda: LambdaClient;
- servicequotas: ServiceQuotasClient;
- sts: STSClient;
-};
-
-export const getServiceClient = <T extends keyof ServiceMapping>({
- region,
- service,
- customCredentials,
-}: {
- region: AwsRegion;
- service: T;
- customCredentials: CustomCredentials<AwsRegion> | null;
-}): ServiceMapping[T] => {
- const Client = (() => {
- if (service === 'cloudwatch') {
- return CloudWatchLogsClient;
- }
-
- if (service === 'lambda') {
- return LambdaClient;
- }
-
- if (service === 's3') {
- return S3Client;
- }
-
- if (service === 'iam') {
- return IAMClient;
- }
-
- if (service === 'servicequotas') {
- return ServiceQuotasClient;
- }
-
- if (service === 'sts') {
- return STSClient;
- }
-
- throw new TypeError('unknown client ' + service);
- })();
-
- const key = getCredentialsHash({
- region,
- customCredentials,
- service,
- });
-
- if (!_clients[key]) {
- checkCredentials();
-
- const lambdaOptions =
- service === 'lambda'
- ? {
- httpsAgent: {
- maxSockets: MAX_FUNCTIONS_PER_RENDER * 2,
- },
- }
- : undefined;
-
- const client = customCredentials
- ? new Client({
- region: customCredentials.region ?? 'us-east-1',
- credentials:
- customCredentials.accessKeyId && customCredentials.secretAccessKey
- ? {
- accessKeyId: customCredentials.accessKeyId,
- secretAccessKey: customCredentials.secretAccessKey,
- }
- : undefined,
- endpoint: customCredentials.endpoint,
- requestHandler: lambdaOptions,
- })
- : process.env.REMOTION_SKIP_AWS_CREDENTIALS_CHECK
- ? new Client({
- region,
- requestHandler: lambdaOptions,
- })
- : new Client({
- region,
- credentials: getCredentials(),
- requestHandler: lambdaOptions,
- });
-
- if (process.env.REMOTION_DISABLE_AWS_CLIENT_CACHE) {
- return client as ServiceMapping[T];
- }
-
- _clients[key] = client;
- }
-
- return _clients[key] as ServiceMapping[T];
-};
+import {getServiceClient} from './get-service-client';
export const getCloudWatchLogsClient = (
region: AwsRegion,
@@ -251,17 +16,6 @@ export const getCloudWatchLogsClient = (
});
};
-export const getS3Client = (
- region: AwsRegion,
- customCredentials: CustomCredentials<AwsRegion> | null,
-): S3Client => {
- return getServiceClient({
- region: customCredentials?.region ?? region,
- service: 's3',
- customCredentials,
- });
-};
-
export const getLambdaClient = (
region: AwsRegion,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
diff --git a/packages/lambda/src/shared/get-credentials.ts b/packages/lambda/src/shared/get-credentials.ts
new file mode 100644
index 0000000000..f9d32f56e7
--- /dev/null
+++ b/packages/lambda/src/shared/get-credentials.ts
@@ -0,0 +1,73 @@
+import {fromIni} from '@aws-sdk/credential-providers';
+import {isInsideLambda} from './is-in-lambda';
+
+type CredentialPair = {
+ accessKeyId: string;
+ secretAccessKey: string;
+ sessionToken?: string;
+};
+type AwsCredentialIdentityProvider = ReturnType<typeof fromIni>;
+
+export const getCredentials = ():
+ | CredentialPair
+ | AwsCredentialIdentityProvider
+ | undefined => {
+ if (isInsideLambda()) {
+ return undefined;
+ }
+
+ if (process.env.REMOTION_AWS_PROFILE) {
+ return fromIni({
+ profile: process.env.REMOTION_AWS_PROFILE,
+ });
+ }
+
+ if (
+ process.env.REMOTION_AWS_ACCESS_KEY_ID &&
+ process.env.REMOTION_AWS_SECRET_ACCESS_KEY &&
+ process.env.REMOTION_AWS_SESSION_TOKEN
+ ) {
+ return {
+ accessKeyId: process.env.REMOTION_AWS_ACCESS_KEY_ID,
+ secretAccessKey: process.env.REMOTION_AWS_SECRET_ACCESS_KEY,
+ sessionToken: process.env.REMOTION_AWS_SESSION_TOKEN,
+ };
+ }
+
+ if (
+ process.env.REMOTION_AWS_ACCESS_KEY_ID &&
+ process.env.REMOTION_AWS_SECRET_ACCESS_KEY
+ ) {
+ return {
+ accessKeyId: process.env.REMOTION_AWS_ACCESS_KEY_ID,
+ secretAccessKey: process.env.REMOTION_AWS_SECRET_ACCESS_KEY,
+ };
+ }
+
+ if (process.env.AWS_PROFILE) {
+ return fromIni({
+ profile: process.env.AWS_PROFILE,
+ });
+ }
+
+ if (
+ process.env.AWS_ACCESS_KEY_ID &&
+ process.env.AWS_SECRET_ACCESS_KEY &&
+ process.env.AWS_SESSION_TOKEN
+ ) {
+ return {
+ accessKeyId: process.env.AWS_ACCESS_KEY_ID as string,
+ secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY as string,
+ sessionToken: process.env.AWS_SESSION_TOKEN as string,
+ };
+ }
+
+ if (process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY) {
+ return {
+ accessKeyId: process.env.AWS_ACCESS_KEY_ID as string,
+ secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY as string,
+ };
+ }
+
+ return undefined;
+};
diff --git a/packages/lambda/src/shared/get-s3-client.ts b/packages/lambda/src/shared/get-s3-client.ts
new file mode 100644
index 0000000000..707029c581
--- /dev/null
+++ b/packages/lambda/src/shared/get-s3-client.ts
@@ -0,0 +1,15 @@
+import type {S3Client} from '@aws-sdk/client-s3';
+import type {CustomCredentials} from '../client';
+import type {AwsRegion} from '../regions';
+import {getServiceClient} from './get-service-client';
+
+export const getS3Client = (
+ region: AwsRegion,
+ customCredentials: CustomCredentials<AwsRegion> | null,
+): S3Client => {
+ return getServiceClient({
+ region: customCredentials?.region ?? region,
+ service: 's3',
+ customCredentials,
+ });
+};
diff --git a/packages/lambda/src/shared/get-service-client.ts b/packages/lambda/src/shared/get-service-client.ts
new file mode 100644
index 0000000000..dc4ff53f6a
--- /dev/null
+++ b/packages/lambda/src/shared/get-service-client.ts
@@ -0,0 +1,170 @@
+import {CloudWatchLogsClient} from '@aws-sdk/client-cloudwatch-logs';
+import {IAMClient} from '@aws-sdk/client-iam';
+import {LambdaClient} from '@aws-sdk/client-lambda';
+import {S3Client} from '@aws-sdk/client-s3';
+import {ServiceQuotasClient} from '@aws-sdk/client-service-quotas';
+import {STSClient} from '@aws-sdk/client-sts';
+import {random} from 'remotion/no-react';
+import type {CustomCredentials} from '../client';
+import type {AwsRegion} from '../regions';
+import {checkCredentials} from './check-credentials';
+import {MAX_FUNCTIONS_PER_RENDER} from './constants';
+import {getCredentials} from './get-credentials';
+
+export type ServiceMapping = {
+ s3: S3Client;
+ cloudwatch: CloudWatchLogsClient;
+ iam: IAMClient;
+ lambda: LambdaClient;
+ servicequotas: ServiceQuotasClient;
+ sts: STSClient;
+};
+
+const getCredentialsHash = ({
+ customCredentials,
+ region,
+ service,
+}: {
+ region: AwsRegion;
+ customCredentials: CustomCredentials<AwsRegion> | null;
+ service: keyof ServiceMapping;
+}): string => {
+ const hashComponents: {[key: string]: unknown} = {};
+
+ if (process.env.REMOTION_SKIP_AWS_CREDENTIALS_CHECK) {
+ hashComponents.credentials = {
+ credentialsSkipped: true,
+ };
+ } else if (process.env.REMOTION_AWS_PROFILE) {
+ hashComponents.credentials = {
+ awsProfile: process.env.REMOTION_AWS_PROFILE,
+ };
+ } else if (
+ process.env.REMOTION_AWS_ACCESS_KEY_ID &&
+ process.env.REMOTION_AWS_SECRET_ACCESS_KEY
+ ) {
+ hashComponents.credentials = {
+ accessKeyId: process.env.REMOTION_AWS_ACCESS_KEY_ID,
+ secretAccessKey: process.env.REMOTION_AWS_SECRET_ACCESS_KEY,
+ };
+ } else if (process.env.AWS_PROFILE) {
+ hashComponents.credentials = {
+ awsProfile: process.env.AWS_PROFILE,
+ };
+ } else if (
+ process.env.AWS_ACCESS_KEY_ID &&
+ process.env.AWS_SECRET_ACCESS_KEY
+ ) {
+ hashComponents.credentials = {
+ accessKeyId: process.env.AWS_ACCESS_KEY_ID as string,
+ secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY as string,
+ };
+ }
+
+ hashComponents.customCredentials = customCredentials;
+ hashComponents.region = region;
+ hashComponents.service = service;
+
+ return random(JSON.stringify(hashComponents)).toString().replace('0.', '');
+};
+
+const _clients: Partial<
+ Record<
+ string,
+ | CloudWatchLogsClient
+ | LambdaClient
+ | S3Client
+ | IAMClient
+ | ServiceQuotasClient
+ | STSClient
+ >
+> = {};
+
+export const getServiceClient = <T extends keyof ServiceMapping>({
+ region,
+ service,
+ customCredentials,
+}: {
+ region: AwsRegion;
+ service: T;
+ customCredentials: CustomCredentials<AwsRegion> | null;
+}): ServiceMapping[T] => {
+ const Client = (() => {
+ if (service === 'cloudwatch') {
+ return CloudWatchLogsClient;
+ }
+
+ if (service === 'lambda') {
+ return LambdaClient;
+ }
+
+ if (service === 's3') {
+ return S3Client;
+ }
+
+ if (service === 'iam') {
+ return IAMClient;
+ }
+
+ if (service === 'servicequotas') {
+ return ServiceQuotasClient;
+ }
+
+ if (service === 'sts') {
+ return STSClient;
+ }
+
+ throw new TypeError('unknown client ' + service);
+ })();
+
+ const key = getCredentialsHash({
+ region,
+ customCredentials,
+ service,
+ });
+
+ if (!_clients[key]) {
+ checkCredentials();
+
+ const lambdaOptions =
+ service === 'lambda'
+ ? {
+ httpsAgent: {
+ maxSockets: MAX_FUNCTIONS_PER_RENDER * 2,
+ },
+ }
+ : undefined;
+
+ const client = customCredentials
+ ? new Client({
+ region: customCredentials.region ?? 'us-east-1',
+ credentials:
+ customCredentials.accessKeyId && customCredentials.secretAccessKey
+ ? {
+ accessKeyId: customCredentials.accessKeyId,
+ secretAccessKey: customCredentials.secretAccessKey,
+ }
+ : undefined,
+ endpoint: customCredentials.endpoint,
+ requestHandler: lambdaOptions,
+ })
+ : process.env.REMOTION_SKIP_AWS_CREDENTIALS_CHECK
+ ? new Client({
+ region,
+ requestHandler: lambdaOptions,
+ })
+ : new Client({
+ region,
+ credentials: getCredentials(),
+ requestHandler: lambdaOptions,
+ });
+
+ if (process.env.REMOTION_DISABLE_AWS_CLIENT_CACHE) {
+ return client as ServiceMapping[T];
+ }
+
+ _clients[key] = client;
+ }
+
+ return _clients[key] as ServiceMapping[T];
+};
diff --git a/packages/lambda/src/shared/lifecycle-rules.ts b/packages/lambda/src/shared/lifecycle-rules.ts
index 985ab656a4..b7223f54ab 100644
--- a/packages/lambda/src/shared/lifecycle-rules.ts
+++ b/packages/lambda/src/shared/lifecycle-rules.ts
@@ -9,7 +9,7 @@ import {
} from '../functions/helpers/apply-lifecyle';
import {getLifeCycleRules} from '../functions/helpers/lifecycle';
import type {AwsRegion} from '../regions';
-import {getS3Client} from './aws-clients';
+import {getS3Client} from './get-s3-client';
const createLCRules = async ({
bucketName,
diff --git a/packages/lambda/src/test/integration/deploy-site.test.ts b/packages/lambda/src/test/integration/deploy-site.test.ts
index 5a1de74087..315b01fe1b 100644
--- a/packages/lambda/src/test/integration/deploy-site.test.ts
+++ b/packages/lambda/src/test/integration/deploy-site.test.ts
@@ -3,7 +3,7 @@ import {deleteSite} from '../../api/delete-site';
import {deploySite} from '../../api/deploy-site';
import {getOrCreateBucket} from '../../api/get-or-create-bucket';
import {getDirFiles} from '../../api/upload-dir';
-import {lambdaLs} from '../../functions/helpers/io';
+import {mockImplementation} from '../mock-implementation';
test('Should throw on wrong prefix', async () => {
await expect(() =>
@@ -110,7 +110,7 @@ test('Should delete the previous site if deploying the new one', async () => {
gitSource: null,
});
- const files = await lambdaLs({
+ const files = await mockImplementation.listObjects({
bucketName,
expectedBucketOwner: null,
prefix: 'sites/testing',
@@ -148,7 +148,7 @@ test('Should keep the previous site if deploying the new one with different ID',
gitSource: null,
});
- const files = await lambdaLs({
+ const files = await mockImplementation.listObjects({
bucketName,
expectedBucketOwner: null,
prefix: 'sites/',
@@ -207,7 +207,7 @@ test('Should not delete site with same prefix', async () => {
siteName: 'my-site',
});
- const files = await lambdaLs({
+ const files = await mockImplementation.listObjects({
bucketName,
expectedBucketOwner: null,
prefix: 'sites/',
diff --git a/packages/lambda/src/test/integration/get-sites.test.ts b/packages/lambda/src/test/integration/get-sites.test.ts
index cf7bfaf9af..ef04f764e3 100644
--- a/packages/lambda/src/test/integration/get-sites.test.ts
+++ b/packages/lambda/src/test/integration/get-sites.test.ts
@@ -1,7 +1,7 @@
import {expect, test} from 'vitest';
-import {deploySite} from '../../api/deploy-site';
-import {getOrCreateBucket} from '../../api/get-or-create-bucket';
-import {getSites, internalGetSites} from '../../api/get-sites';
+import {internalDeploySite} from '../../api/deploy-site';
+import {internalGetOrCreateBucket} from '../../api/get-or-create-bucket';
+import {internalGetSites} from '../../api/get-sites';
import {mockImplementation} from '../mock-implementation';
test('Should have no buckets at first', async () => {
@@ -14,16 +14,25 @@ test('Should have no buckets at first', async () => {
});
test('Should have a site after deploying', async () => {
- await getOrCreateBucket({
+ await internalGetOrCreateBucket({
region: 'eu-central-1',
+ providerSpecifics: mockImplementation,
+ customCredentials: null,
+ enableFolderExpiry: null,
});
expect(
- await deploySite({
+ await internalDeploySite({
bucketName: 'remotionlambda-eucentral1-abcdef',
entryPoint: 'first',
region: 'eu-central-1',
siteName: 'testing',
gitSource: null,
+ logLevel: 'info',
+ indent: false,
+ providerSpecifics: mockImplementation,
+ privacy: 'public',
+ throwIfSiteExists: true,
+ options: {},
}),
).toEqual({
serveUrl:
@@ -35,7 +44,12 @@ test('Should have a site after deploying', async () => {
uploadedFiles: 2,
},
});
- expect(await getSites({region: 'eu-central-1'})).toEqual({
+ expect(
+ await internalGetSites({
+ region: 'eu-central-1',
+ providerSpecifics: mockImplementation,
+ }),
+ ).toEqual({
buckets: [
{
creationDate: 0,
diff --git a/packages/lambda/src/test/integration/renders/muted-render.test.ts b/packages/lambda/src/test/integration/renders/muted-render.test.ts
index 50c5d96921..d54c8e5db3 100644
--- a/packages/lambda/src/test/integration/renders/muted-render.test.ts
+++ b/packages/lambda/src/test/integration/renders/muted-render.test.ts
@@ -5,7 +5,7 @@ import path from 'path';
import {afterAll, expect, test} from 'vitest';
import {deleteRender} from '../../../api/delete-render';
import {rendersPrefix} from '../../../defaults';
-import {lambdaLs} from '../../../functions/helpers/io';
+import {mockImplementation} from '../../mock-implementation';
import {simulateLambdaRender} from '../simulate-lambda-render';
afterAll(async () => {
@@ -47,7 +47,7 @@ test('Should make muted render audio', async () => {
unlinkSync(tmpfile);
- const files = await lambdaLs({
+ const files = await mockImplementation.listObjects({
bucketName: progress.outBucket as string,
region: 'eu-central-1',
expectedBucketOwner: 'abc',
@@ -62,7 +62,7 @@ test('Should make muted render audio', async () => {
renderId,
});
- const expectFiles = await lambdaLs({
+ const expectFiles = await mockImplementation.listObjects({
bucketName: progress.outBucket as string,
region: 'eu-central-1',
expectedBucketOwner: 'abc',
diff --git a/packages/lambda/src/test/integration/renders/regular-audio.test.ts b/packages/lambda/src/test/integration/renders/regular-audio.test.ts
index 756cba46c8..b3e5c147dc 100644
--- a/packages/lambda/src/test/integration/renders/regular-audio.test.ts
+++ b/packages/lambda/src/test/integration/renders/regular-audio.test.ts
@@ -4,7 +4,7 @@ import path from 'path';
import {afterAll, expect, test} from 'vitest';
import {deleteRender} from '../../../api/delete-render';
import {rendersPrefix} from '../../../defaults';
-import {lambdaLs} from '../../../functions/helpers/io';
+import {mockImplementation} from '../../mock-implementation';
import {Wavedraw} from '../draw-wav';
import {simulateLambdaRender} from '../simulate-lambda-render';
@@ -50,7 +50,7 @@ test('Should make regular (non-seamless) audio', async () => {
wd.drawWave(options); // outputs wave drawing to example1.png
- const files = await lambdaLs({
+ const files = await mockImplementation.listObjects({
bucketName: progress.outBucket as string,
region: 'eu-central-1',
expectedBucketOwner: 'abc',
@@ -65,7 +65,7 @@ test('Should make regular (non-seamless) audio', async () => {
renderId,
});
- const expectFiles = await lambdaLs({
+ const expectFiles = await mockImplementation.listObjects({
bucketName: progress.outBucket as string,
region: 'eu-central-1',
expectedBucketOwner: 'abc',
diff --git a/packages/lambda/src/test/integration/renders/seamless-audio.test.ts b/packages/lambda/src/test/integration/renders/seamless-audio.test.ts
index 00347db05d..e1ad0af0ea 100644
--- a/packages/lambda/src/test/integration/renders/seamless-audio.test.ts
+++ b/packages/lambda/src/test/integration/renders/seamless-audio.test.ts
@@ -4,7 +4,7 @@ import path from 'path';
import {afterAll, expect, test} from 'vitest';
import {deleteRender} from '../../../api/delete-render';
import {rendersPrefix} from '../../../defaults';
-import {lambdaLs} from '../../../functions/helpers/io';
+import {mockImplementation} from '../../mock-implementation';
import {Wavedraw} from '../draw-wav';
import {simulateLambdaRender} from '../simulate-lambda-render';
@@ -62,7 +62,7 @@ test('Should make seamless audio', async () => {
await wd.drawWave(options); // outputs wave drawing to example1.png
- const files = await lambdaLs({
+ const files = await mockImplementation.listObjects({
bucketName: progress.outBucket as string,
region: 'eu-central-1',
expectedBucketOwner: 'abc',
@@ -77,7 +77,7 @@ test('Should make seamless audio', async () => {
renderId,
});
- const expectFiles = await lambdaLs({
+ const expectFiles = await mockImplementation.listObjects({
bucketName: progress.outBucket as string,
region: 'eu-central-1',
expectedBucketOwner: 'abc',
diff --git a/packages/lambda/src/test/integration/renders/slow-seamless-audio.test.ts b/packages/lambda/src/test/integration/renders/slow-seamless-audio.test.ts
index 47f0416baf..780c287c28 100644
--- a/packages/lambda/src/test/integration/renders/slow-seamless-audio.test.ts
+++ b/packages/lambda/src/test/integration/renders/slow-seamless-audio.test.ts
@@ -4,7 +4,7 @@ import path from 'path';
import {afterAll, expect, test} from 'vitest';
import {deleteRender} from '../../../api/delete-render';
import {rendersPrefix} from '../../../defaults';
-import {lambdaLs} from '../../../functions/helpers/io';
+import {mockImplementation} from '../../mock-implementation';
import {Wavedraw} from '../draw-wav';
import {simulateLambdaRender} from '../simulate-lambda-render';
@@ -62,7 +62,7 @@ test('Should make slowed down seamless audio', async () => {
wd.drawWave(options); // outputs wave drawing to example1.png
- const files = await lambdaLs({
+ const files = await mockImplementation.listObjects({
bucketName: progress.outBucket as string,
region: 'eu-central-1',
expectedBucketOwner: 'abc',
@@ -77,7 +77,7 @@ test('Should make slowed down seamless audio', async () => {
renderId,
});
- const expectFiles = await lambdaLs({
+ const expectFiles = await mockImplementation.listObjects({
bucketName: progress.outBucket as string,
region: 'eu-central-1',
expectedBucketOwner: 'abc',
diff --git a/packages/lambda/src/test/integration/renders/transparent-webm.test.ts b/packages/lambda/src/test/integration/renders/transparent-webm.test.ts
index d5dd81568d..f145da8111 100644
--- a/packages/lambda/src/test/integration/renders/transparent-webm.test.ts
+++ b/packages/lambda/src/test/integration/renders/transparent-webm.test.ts
@@ -5,7 +5,7 @@ import path from 'node:path';
import {afterAll, expect, test} from 'vitest';
import {deleteRender} from '../../../api/delete-render';
import {rendersPrefix} from '../../../defaults';
-import {lambdaLs} from '../../../functions/helpers/io';
+import {mockImplementation} from '../../mock-implementation';
import {simulateLambdaRender} from '../simulate-lambda-render';
afterAll(async () => {
@@ -46,7 +46,7 @@ test('Should make a transparent video', async () => {
expect(probe.stderr).toMatch(/Audio: opus, 48000 Hz/);
fs.unlinkSync(out);
- const files = await lambdaLs({
+ const files = await mockImplementation.listObjects({
bucketName: progress.outBucket as string,
region: 'eu-central-1',
expectedBucketOwner: 'abc',
@@ -61,7 +61,7 @@ test('Should make a transparent video', async () => {
renderId,
});
- const expectFiles = await lambdaLs({
+ const expectFiles = await mockImplementation.listObjects({
bucketName: progress.outBucket as string,
region: 'eu-central-1',
expectedBucketOwner: 'abc',
diff --git a/packages/lambda/src/test/mock-implementation.ts b/packages/lambda/src/test/mock-implementation.ts
index 87f6a3be43..81bfd98eda 100644
--- a/packages/lambda/src/test/mock-implementation.ts
+++ b/packages/lambda/src/test/mock-implementation.ts
@@ -1,6 +1,10 @@
import type {ProviderSpecifics} from '@remotion/serverless';
import type {AwsRegion} from '../regions';
-import {addMockBucket, getMockBuckets} from './mocks/mock-store';
+import {
+ addMockBucket,
+ getMockBuckets,
+ getS3FilesInBucket,
+} from './mocks/mock-store';
export const mockImplementation: ProviderSpecifics<AwsRegion> = {
applyLifeCycle: () => Promise.resolve(),
@@ -18,4 +22,31 @@ export const mockImplementation: ProviderSpecifics<AwsRegion> = {
return Promise.resolve();
},
getBuckets: () => Promise.resolve(getMockBuckets()),
+ listObjects: (input) => {
+ if (!input) {
+ throw new Error('need to pass input');
+ }
+
+ const files = getS3FilesInBucket({
+ bucketName: input.bucketName,
+ region: input.region,
+ });
+
+ return Promise.resolve(
+ files
+ .filter((p) => p.key.startsWith(input.prefix))
+ .map((file) => {
+ const size =
+ typeof file.content === 'string' ? file.content.length : 0;
+ return {
+ Key: file.key,
+ ETag: 'etag',
+ LastModified: new Date(0),
+ Owner: undefined,
+ Size: size,
+ StorageClass: undefined,
+ };
+ }),
+ );
+ },
};
diff --git a/packages/lambda/src/test/mocks/mock-store.ts b/packages/lambda/src/test/mocks/mock-store.ts
index bb947dafd4..a4189bdf37 100644
--- a/packages/lambda/src/test/mocks/mock-store.ts
+++ b/packages/lambda/src/test/mocks/mock-store.ts
@@ -1,7 +1,20 @@
+import type {Privacy} from '@remotion/serverless/client';
+import type {ReadStream} from 'node:fs';
import type {BucketWithLocation} from '../../api/get-buckets';
+import type {AwsRegion} from '../../regions';
export const mockBucketStore: BucketWithLocation[] = [];
+type S3MockFile = {
+ bucketName: string;
+ region: AwsRegion;
+ acl: 'public-read' | 'private' | 'none';
+ key: string;
+ content: string | ReadStream;
+};
+
+let mockS3Store: S3MockFile[] = [];
+
export const addMockBucket = (bucket: BucketWithLocation) => {
mockBucketStore.push(bucket);
};
@@ -15,3 +28,78 @@ export const mockBucketExists = (bucketName: string, region: string) => {
mockBucketStore.find((s) => s.name === bucketName && s.region === region),
);
};
+
+export const getS3FilesInBucket = ({
+ bucketName,
+ region,
+}: {
+ bucketName: string;
+ region: string;
+}) => {
+ return mockS3Store.filter(
+ (s) => s.bucketName === bucketName && s.region === region,
+ );
+};
+
+export const writeMockS3File = ({
+ body,
+ privacy,
+ bucketName,
+ key,
+ region,
+}: {
+ body: string | ReadStream;
+ privacy: Privacy;
+ bucketName: string;
+ key: string;
+ region: AwsRegion;
+}) => {
+ mockS3Store = mockS3Store.filter((m) => {
+ return !(
+ m.region === region &&
+ m.bucketName === bucketName &&
+ m.key === key
+ );
+ });
+ mockS3Store.push({
+ content: body,
+ acl:
+ privacy === 'no-acl'
+ ? 'none'
+ : privacy === 'public'
+ ? 'public-read'
+ : 'private',
+ bucketName,
+ key,
+ region,
+ });
+};
+
+export const readMockS3File = ({
+ region,
+ key,
+ bucketName,
+}: {
+ region: AwsRegion;
+ key: string;
+ bucketName: string;
+}) => {
+ return mockS3Store.find(
+ (s) => s.key === key && s.region === region && s.bucketName === bucketName,
+ );
+};
+
+export const mockDeleteS3File = ({
+ key,
+ region,
+ bucketName,
+}: {
+ key: string;
+ region: AwsRegion;
+ bucketName: string;
+}) => {
+ mockS3Store = mockS3Store.filter(
+ (s) =>
+ !(s.bucketName === bucketName && s.key === key && s.region === region),
+ );
+};
diff --git a/packages/serverless/src/provider-implementation.ts b/packages/serverless/src/provider-implementation.ts
index e4736f97c5..74d11c8663 100644
--- a/packages/serverless/src/provider-implementation.ts
+++ b/packages/serverless/src/provider-implementation.ts
@@ -23,6 +23,21 @@ type ApplyLifeCycle<Region extends string> = (params: {
customCredentials: CustomCredentials<Region> | null;
}) => Promise<void>;
+type BucketObject = {
+ Key: string;
+ LastModified: Date;
+ ETag: string;
+ Size: number;
+};
+
+type ListObjects<Region extends string> = (params: {
+ bucketName: string;
+ prefix: string;
+ region: Region;
+ expectedBucketOwner: string | null;
+ continuationToken?: string;
+}) => Promise<BucketObject[]>;
+
export type ProviderSpecifics<Region extends string> = {
getChromiumPath: () => string | null;
getCurrentRegionInFunction: () => Region;
@@ -30,4 +45,5 @@ export type ProviderSpecifics<Region extends string> = {
getBuckets: GetBuckets<Region>;
createBucket: CreateBucket<Region>;
applyLifeCycle: ApplyLifeCycle<Region>;
+ listObjects: ListObjects<Region>;
};