Skip to content

AWS S3 PutObjectCommand extremely slow #27841

@HuakunShen

Description

@HuakunShen

Version: Deno 2.1.7

I am using "@aws-sdk/client-s3": "npm:@aws-sdk/[email protected]", to upload files to S3.

Here is sample code, uploading a 4KB file takes 6 seconds. The time is taken on step s3Client.send(command);.

I also tried uploading a 100MB file, took ~7.5 second. So the upload speed seems fine. Could it be issue with connection establish?

I ran the same code with bun, took 0.8ms to upload a 4KB file.

import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3';

// Configure the S3 client
const s3Client = new S3Client({
	region: Deno.env.get('AWS_REGION') || 'us-east-1',
	credentials: {
		accessKeyId: Deno.env.get('AWS_ACCESS_KEY_ID') || '',
		secretAccessKey: Deno.env.get('AWS_SECRET_ACCESS_KEY') || ''
	}
});

// Function to upload a file to S3
async function uploadFileToS3(bucketName: string, key: string, filePath: string) {
	try {
		// Read the file
		const fileContent = await Deno.readFile(filePath);

		const command = new PutObjectCommand({
			Bucket: bucketName,
			Key: key,
			Body: fileContent
		});
		console.time('send');
		const response = await s3Client.send(command);
		console.timeEnd('send');
		console.log('File uploaded successfully:', response);
	} catch (error) {
		console.error('Error uploading file:', error);
		throw error; // Re-throw the error for better error handling
	}
}

// Example usage
const bucketName = Deno.env.get('AWS_BUCKET_NAME') || '';
await uploadFileToS3(
	bucketName,
	'wacv24-2686.mp4',
	'/Users/hk/Downloads/wacv24-2686.mp4'
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working correctlynode compat

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions