We announced
Setting Credentials in Node.js
There are several ways in Node.js to supply your credentials to the SDK. Some of these are more secure and others afford greater convenience while developing an application. When obtaining credentials in Node.js, be careful about relying on more than one source such as an environment variable and a JSON file you load. You can change the permissions under which your code runs without realizing the change has happened.
Here are the ways you can supply your credentials in order of recommendation:
-
Loaded from AWS Identity and Access Management (IAM) roles for Amazon EC2
-
Loaded from the shared credentials file (
~/.aws/credentials
) -
Loaded from environment variables
-
Loaded from a JSON file on disk
-
Other credential-provider classes provided by the JavaScript SDK
If more than one credential source is available to the SDK, the default precedence of selection is as follows:
-
Credentials that are explicitly set through the service-client constructor
-
Environment variables
-
The shared credentials file
-
Credentials loaded from the ECS credentials provider (if applicable)
-
Credentials that are obtained by using a credential process specified in the shared AWS config file or the shared credentials file. For more information, see Loading Credentials in Node.js using a Configured Credential Process.
-
Credentials loaded from AWS IAM using the credentials provider of the Amazon EC2 instance (if configured in the instance metadata)
For more information, see Class: AWS.Credentials
and Class: AWS.CredentialProviderChain
in the API reference.
Warning
While it is possible to do so, we do not recommend hard-coding your AWS credentials in your application. Hard-coding credentials poses a risk of exposing your access key ID and secret access key.
The topics in this section describe how to load credentials into Node.js.
Topics
- Loading Credentials in Node.js from IAM roles for Amazon EC2
- Loading Credentials for a Node.js Lambda Function
- Loading Credentials in Node.js from the Shared Credentials File
- Loading Credentials in Node.js from Environment Variables
- Loading Credentials in Node.js from a JSON File
- Loading Credentials in Node.js using a Configured Credential Process