Search code examples
amazon-web-servicessingle-sign-onaws-sdk-jsaws-sdk-nodejs

AWS: Unable to login into aws-sdk using sso credentials


I am trying to access AWS resources with AWS-SDK using SSO credentials from the node.js application. For this, first I have created my SSO profile from AWS CLI and then I am trying to use same profile in the application I have tried using following ways:

Option1:
const AWS = require("aws-sdk");
const { defaultProvider } = require("@aws-sdk/credential-provider-node");
const route53 = new AWS.Route53({ credentials: defaultProvider({ profile: "my-sso-profile" })});

Option2:
const AWS = require("aws-sdk");
const { fromSSO } = require("@aws-sdk/credential-provider-sso");
const route53 = new AWS.Route53({ credentials: fromSSO ({ profile: "my-sso-profile" })});

I am running with following error:

Error [CredentialsError]: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1

Even I have set environment variable AWS_SDK_LOAD_CONFIG as 1 using(setx AWS_SDK_LOAD_CONFIG 1). Still I am facing the same issue

My config file located at users/user/.aws/config looks like following:

[profile my-sso-profile]
sso_start_url = https://*******.awsapps.com/start
sso_region = us-east-1
sso_account_id = *********
sso_role_name = PowerUserAccess
region = us-east-1
output = json

Is there any other way to use SSO credentials or any change required in the above code?


Solution

  • Issue resolved, As fromSSO which am using to retrieve credentials is returning a anonymous function which is going to return a promise, I just modified the code as below:

    const { fromSSO } = require("@aws-sdk/credential-provider-sso");
    const credentials = await fromSSO({ profile: "default" })();
    const route53 = new AWS.Route53({ credentials: credentials});