How to use the AWS S3 JS SDK with Wasabi Cloud ?

  • Modifié il y à12 mois 
  • Temps de lecture :1Minute

How to use @aws-sdk/client-s3 with Wasabi Cloud S3

ACCESS_KEY_ID et SECRET_ACCESS_KEY must be created on your Wasabi console.

WASABI_ENDPOINT must be of the format : https://s3.<bucket_region>.wasabisys.com .

S3-wasabi-client.mjs example

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

const { 
	S3_REGION = 'us-east-1',
	ACCESS_KEY_ID="YOUR ACCESS KEY",
	SECRET_ACCESS_KEY="YOUR SECRET ACCESS KEY",
	WASABI_ENDPOINT="https://s3.eu-west-2.wasabisys.com"
 } = process.env;

const s3WasabiClient = new S3Client({
    region: S3_REGION,
    apiVersion: '2006-03-01',
    credentials: {
        accessKeyId: ACCESS_KEY_ID,
        secretAccessKey: SECRET_ACCESS_KEY
    },
    endpoint: WASABI_ENDPOINT
});

export { s3WasabiClient };

List all objects in the bucket “bucket_name”

import { s3WasabiClient } from './s3-wasabi-client.mjs';
import { ListObjectsCommand } from '@aws-sdk/client-s3';

const listObjectsCommand = new ListObjectsCommand('bucket_name', '');
const data = await s3WasabiClient.send(listObjectsCommand);
if(data.Contents) {
	console.log('data : ', data.Contents);
}

1 réflexion au sujet de « How to use the AWS S3 JS SDK with Wasabi Cloud ? »

Laisser un commentaire