1

I'm using v3 of aws-sdk, trying to follow the reference docs exactly, but cannot load credentials.

const {fromIni} = require("@aws-sdk/credential-provider-ini");

const credentials = fromIni({});

... gives the error:

Unhandled Rejection (Error): Profile default could not be found or parsed in shared credentials file.

And:

const {parseKnownFiles} = require("@aws-sdk/credential-provider-ini");

const pkf = parseKnownFiles();

... gives the error that I think may be the cause:

TypeError: Cannot read property 'loadedConfig' of undefined

If it can't find a known credentials file then it's certainly not going to find default in there.

Yet I'm certain the credentials are there:

PS C:\> aws sts get-caller-identity --profile="default"
{
    "UserId": "*********************",
    "Account": "************",
    "Arn": "arn:aws:iam::************:user/*****"
}

How do I load my credentials in aws-sdk v3?

weegolo
  • 354
  • 2
  • 14

3 Answers3

2

You need to pass AWS profile into fromIni(). It is default in your case.

const {fromIni} = require("@aws-sdk/credential-provider-ini");

const credentials = fromIni({profile: 'default'});
Sedat Polat
  • 1,631
  • 2
  • 18
  • 28
0

I've been struggling too with the shared credential files. I know this is not the appropriate way due to security reasons, but you could try the following example in case you are pressured by time:

const client = new LexRuntimeV2Client({
    region: process.env.REACT_APP_AWS_REGION,
    credentials: {
        accessKeyId: process.env.REACT_APP_AWS_ACCESS_KEY,
        secretAccessKey: process.env.REACT_APP_AWS_SECRET_ACCESS_KEY
    },
});

In the snippet I am using environment variables and a particular client(AWS Lex) but you can substitute those for your keys, region, and client. I don't recommend hard coding your keys, but during development this should work fine as a temporary solution.

Magraz
  • 11
  • 1
    Thanks for helping, but I'm downvoting you because I'm security guy! If you're too pressured for time to get it right now, you're probably going to be too pressured for time to ever go back and fix it, and that's how security vulnerabilities get into software. – weegolo Mar 10 '22 at 03:36
0

i had the same problem just follow these steps

https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials_profiles.html

place a .aws folder with the credentials file in home (linux) or %UserProfile% (windows)