Search code examples
javascriptnode.jsaws-sdk-nodejs

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.


Solution

  • 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');