0

I'm using AWS for executing some functionalities of our project. Here's the AWS configuration that's being implemented on our project file.

const aws = require('aws-sdk');
const lambda = new aws.Lambda({ region: 'us-west-2' });
const AWS_REGION = 'us-west-2';
aws.config.update({ region: AWS_REGION });
aws.config.update({ accessKeyId: 'MYKEYID', secretAccessKey: 'MYSECRETACCESSKEY' });

now, when I consume aws, for my functionality here

lambda.invoke({
                FunctionName: "html-to-pdf", //all environments to call this same utility function. Don't prefix with dev-, prod-
                InvocationType: 'RequestResponse',
                Payload: s({ html_base64: base64data })
            }

It gives me an error like this,

convertHtmlToPdf.err CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
    at Timeout.connectTimeout [as _onTimeout] (D:\NEW\NEW\Web\thirdparty-api\node_modules\aws-sdk\lib\http\node.js:69:15)
    at listOnTimeout (internal/timers.js:557:17)
    at processTimers (internal/timers.js:500:7)
generateDocument.err Error [CredentialsError]: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
    at Timeout.connectTimeout [as _onTimeout] (D:\NEW\NEW\Web\thirdparty-api\node_modules\aws-sdk\lib\http\node.js:69:15)
    at listOnTimeout (internal/timers.js:557:17)
    at processTimers (internal/timers.js:500:7) {
  code: 'CredentialsError',
  time: 2022-06-01T15:38:10.355Z,
  retryable: true,
  originalError: {
    message: 'Could not load credentials from any providers',
    code: 'CredentialsError',
    time: 2022-06-01T15:38:10.355Z,
    retryable: true,
    originalError: {
      message: 'EC2 Metadata roleName request returned error',
      code: 'TimeoutError',
      time: 2022-06-01T15:38:10.354Z,
      retryable: true,
      originalError: [Object]
    }
  },
  errorLocation: 'generateDocument'
}

As you can see, I've already configured AWS parameters at the top of the file but still it is throwing me this error. I'm clueless here, Why is it throwing me an error when I've already configured it?

Any help is highly appreciated.

Chirag
  • 994
  • 2
  • 11
  • 26
  • I would check the config file if the credentials are actually there or not. I would then set the credentials manually in the config file and see if the error repeats. – Myz Jun 01 '22 at 17:16
  • config file at what place? in my system? – Chirag Jun 01 '22 at 17:29
  • Yes, if you are running your code from your system and using config file from your system. For Windows, C:\Users\USER_NAME\.aws\config and for Linux os macOS: ~/.aws/config Ref: https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-region.html#setting-region-config-file – Myz Jun 01 '22 at 17:35
  • As you could see, I've already configured my credentials at the top of my js file. Do I still need to add config file in my system? – Chirag Jun 01 '22 at 17:51
  • By default, the SDK detects AWS credentials set in your environment and uses them to sign requests to AWS. That way you don’t need to manage credentials in your applications. You can try to set these credentials manually in your environment by export (in linux e.g. export AWS_ACCESS_KEY_ID="your_key_id") and set command (in Windows e.g. export AWS_SECRET_ACCESS_KEY="your_secret_key"). Alternatively, you can also create .aws/credentials file in your system and use that instead in your code. This will give you good idea why your code is failing to load credentials in the first place. – Myz Jun 01 '22 at 18:14
  • Checked my system in given location. There is .aws folder and inside that there is a config file where same access_key and secret_key is present. Then why I'm still getting error? I mean, I cross checked to see if things are present as you guided and yeah it's there. But still it's throwing me same error. – Chirag Jun 01 '22 at 18:29
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/245243/discussion-between-chirag-and-myz). – Chirag Jun 01 '22 at 19:43

0 Answers0