How can I change .aws credentials path ? nodejs (aws-sdk)

To connect aws-sdk (nodejs) to aws I have to create credentials file then add accessKeyId and secretAccessKey at

C:\Users{username}.aws\credentials

But I would like to change path .aws to somewhere else or create const variables of accessKeyId and secretAccessKey in js.

Can someone show me how can I change path ? or add accessKeyId and secretAccessKey somewhere inside js.

thank you.

Upvotes: 0

Views: 776

Answers (2)

Another solution is to user AWS Environment variables:

https://docs.aws.amazon.com/cli/latest/userguide/cli-environment.html

Using this way you warantee AWS Runtime environment compatibility.

Upvotes: 0

Torab Shaikh
Torab Shaikh

Reputation: 456

You can create a JSON file containing your credentials like this

{
    "accessKeyId": " Your Access Key Id", 
    "secretAccessKey": "Your Secret Access Key",
    "region": "Your Region"
}

and save it. then give path of this JSON file using

var AWS = require('aws-sdk');
AWS.config.loadFromPath('File_Path/file_name.json');

Upvotes: 1

Related Questions