Search code examples
amazon-web-servicesamazon-s3aws-sdkaws-sdk-js

'Credential is missing' Error On Instantiating S3 Class Using AWS-SDK JS V3


I am getting en error when creating S3 client from class S3 in newer v3 of aws-sdk javascript.

I add aws config parameters including credentials obtained from aws sts when user gets authenticated (assuming a role with permission to call getObject) at service-level (when instantiating S3 class) along with other parameters. See my code below:

const { S3, ... } = require("@aws-sdk/client-s3");

someFunc();
function someFunc(authUserCredentials) {
 ...
 try {

   const { AccessKeyid, SecretKey, SessionToken } = authUserCredentials;
   const s3Client = new S3({
                      signatureVersion: 'v4',
                      accessKeyId: AccessKeyId,
                      secretAccessKey: SecretKey,
                      sessionToken: SessionToken,
                      region: 'us-east-1',
   });

   console.log(s3Client.config);
   ...

 }catch(e) {
     console.error(e);
 }
}

I checked the class S3 code in aws-sdk-js-v3 repo, and there doesn't seem to be no 'Credential' constructor config argument required. Am I doing something wrong?


Solution

  • According to the documentation for the constructor these arguments are valid.

    There is still an argument name for the Credential object with the name credentials. If you instantiate a AWS.Credentials object you can pass this into that argument.