Search code examples
aws-sdkaws-sdk-js

Is there a way to pass the accessKeyId and the secretKey to the aws-sdk v3 as a String?


I'm looking to call EC2 with a provided AWSkeyId and secret (stored, encrypted in DB) I cannot find a way to pass them as a string.

I'm trying to use the @aws-sdk/credential-providers package.

But looking at this: https://github.com/aws/aws-sdk-js-v3/blob/main/packages/credential-provider-node/src/defaultProvider.ts there is no way to use the defaultProvider.

Is there any other way to do that? appreciate the help.


Solution

  • Well apparently there is no need to use the defaultProvider, as you can pass the credentials in any of was clients this way :

            const credentials = {
                accessKeyId: this.awsAccessKey,
                secretAccessKey: this.awsAccessSecret
            };
    
            this.ec2 = new EC2Client({ region: this.region, credentials });