Loading Credentials in Node.js from a JSON File - Amazon SDK for JavaScript
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

We announced the upcoming end-of-support for Amazon SDK for JavaScript v2. We recommend that you migrate to Amazon SDK for JavaScript v3. For dates, additional details, and information on how to migrate, please refer to the linked announcement.

Loading Credentials in Node.js from a JSON File

You can load configuration and credentials from a JSON document on disk using AWS.config.loadFromPath. The path specified is relative to the current working directory of your process. For example, to load credentials from a 'config.json' file with the following content:

{ "accessKeyId": <YOUR_ACCESS_KEY_ID>, "secretAccessKey": <YOUR_SECRET_ACCESS_KEY>, "region": "us-east-1" }

Use the following command:

AWS.config.loadFromPath('./config.json');
Note

Loading configuration data from a JSON document resets all existing configuration data. Add additional configuration data after using this technique. Loading credentials from a JSON document is not supported in browser scripts.