lundi 20 janvier 2020

Using Same s3 instance ( "aws-sdk" ) with varying the credentials on each request

The case :

  • I have multi-tenant system, and each tenant has his bucket and accessKeyId and accessSecret, and I am creating a wrapper above AWS.S3 to extend some functionality.

Can i use same instance of s3 client but alter the credentials based on the requesting user credentials?

Like this :

class S3Storage {
 private readonly s3: AWS.S3;

 constructor(config: S3Config) {
     this.s3 = new AWS.S3({
       accessKeyId: config.accessKeyId,
       secretAccessKey: config.secretAccessKey,
       apiVersion: config.apiVersion,
       region: config.region
     });
   }

 public myDownload (key: string, userData: any) {
  // alter credentials for this.s3 for the userData
 }
}

Or should i create s3 client (with provided userData) every time myDownload function is invoked.

Aucun commentaire:

Enregistrer un commentaire