Skip to content

🎥 Make videos programmatically with React

`@remotion/lambda`: Better Lambda upload concurrency

Jonny Burgerb1ef7451ba48
diff --git a/packages/lambda/src/api/upload-dir.ts b/packages/lambda/src/api/upload-dir.ts
index b759757140..b49e64e923 100644
--- a/packages/lambda/src/api/upload-dir.ts
+++ b/packages/lambda/src/api/upload-dir.ts
@@ -6,8 +6,8 @@ import path from 'node:path';
import type {Privacy} from '../defaults';
import type {AwsRegion} from '../pricing/aws-regions';
import {getS3Client} from '../shared/aws-clients';
-import {chunk} from '../shared/chunk';
import {makeS3Key} from '../shared/make-s3-key';
+import {pLimit} from '../shared/p-limit';
type FileInfo = {
name: string;
@@ -71,6 +71,8 @@ async function getFiles(
return _files.flat(1);
}
+const limit = pLimit(50);
+
export const uploadDir = async ({
bucket,
region,
@@ -96,11 +98,9 @@ export const uploadDir = async ({
const client = getS3Client(region, null);
- const chunkedFiles = chunk(files, 200);
-
const uploadAll = (async () => {
- for (const filesChunk of chunkedFiles) {
- const uploads = filesChunk.map((filePath) => {
+ const uploads = files.map((filePath) =>
+ limit(async () => {
const Key = makeS3Key(keyPrefix, localDir, filePath.name);
const Body = createReadStream(filePath.name);
const ContentType = mimeTypes.lookup(Key) || 'application/octet-stream';
@@ -126,10 +126,11 @@ export const uploadDir = async ({
paralellUploads3.on('httpUploadProgress', (progress) => {
progresses[filePath.name] = progress.loaded ?? 0;
});
- return paralellUploads3.done();
- });
- await Promise.all(uploads);
- }
+ const prom = await paralellUploads3.done();
+ return prom;
+ }),
+ );
+ await Promise.all(uploads);
})();
const interval = setInterval(() => {