Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not load credentials from any providers in NodeJS

I am using AWSservices so I am using 'aws-sdk' package for nodeJS. As per their instructions on official website they ask to create a .aws folder in your current user profile and create credentials file there with secrete and access key in it.

AWS doc link -

https://aws.amazon.com/developers/getting-started/nodejs/

I follow the same procedure on windows and ubuntu. In windows AWS services are working fine but when I upload my code setup to AWS ubuntu instance it start giving me following error.

{
  "message": "Missing credentials in config",
  "retryable": false,
  "time": "2019-05-13T12:34:45.834Z",
  "code": "CredentialsError",
  "originalError": {
    "message": "Could not load credentials from any providers",
    "retryable": false,
    "time": "2019-05-13T12:34:45.834Z",
    "code": "CredentialsError"
  }
}

Here is code where I include 'aws-sdk' in JS file.

const AWS = require('aws-sdk');

const {
  saveUserTokens,
  updateMigratedUser
} = require('./databaseOperations');

const AWS_REGION = "us-west-2";
const CLIENT_ID = "5f70t79un9ep945645k5rooqocr4mfg";
const USER_POOL_ID = "us-west-2_xxxxx";

AWS.config.update({ region: AWS_REGION });
const cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();

console log of AWS.config object -

Config {
  credentials:
   SharedIniFileCredentials {
     expired: false,
     expireTime: null,
     refreshCallbacks: [],
     accessKeyId: 'XXXXXXXXXXXXXXX',
     sessionToken: undefined,
     filename: undefined,
     profile: 'default',
     disableAssumeRole: true,
     preferStaticCredentials: false,
     tokenCodeFn: null,
     httpOptions: null },
  credentialProvider:
   CredentialProviderChain {
     providers:
      [ [Function],
        [Function],
        [Function],
        [Function],
        [Function],
        [Function] ],
     resolveCallbacks: [] },
  region: 'us-west-2',
  logger: null,
  apiVersions: {},
  apiVersion: null,
  endpoint: undefined,
  httpOptions: { timeout: 120000 },
  maxRetries: undefined,
  maxRedirects: 10,
  paramValidation: true,
  sslEnabled: true,
  s3ForcePathStyle: false,
  s3BucketEndpoint: false,
  s3DisableBodySigning: true,
  computeChecksums: true,
  convertResponseTypes: true,
  correctClockSkew: false,
  customUserAgent: null,
  dynamoDbCrc32: true,
  systemClockOffset: 0,
  signatureVersion: null,
  signatureCache: true,
  retryDelayOptions: {},
  useAccelerateEndpoint: false,
  clientSideMonitoring: false,
  endpointDiscoveryEnabled: false,
  endpointCacheSize: 1000,
  hostPrefixEnabled: true }
like image 291
Rajnesh Thakur Avatar asked Nov 06 '22 17:11

Rajnesh Thakur


1 Answers

Issue is resolved. I deleted the .aws/credentials. Again create them with AWS CLI as a root user. There is two hurdles in this.

First one is - I am using pm2 to run my node server. It is running multiple instances of a server as a root user as well as with another user profile also.

Second might be related to user access. Still not sure why its not reading credentials from file which is already present there. I have created environment variables also. I already have two providers but still it's not picking keys from them....

Below is the doc link for anyone facing this issue related to providers.

https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html#cli-quick-configuration

like image 52
Rajnesh Thakur Avatar answered Nov 13 '22 15:11

Rajnesh Thakur