Skip to content

Instantly share code, notes, and snippets.

@wancw
Forked from pahud/aws-get-credentials.js
Created July 9, 2016 15:52
Show Gist options
  • Save wancw/cb774528c95288bd3dc4a21f485a71d5 to your computer and use it in GitHub Desktop.
Save wancw/cb774528c95288bd3dc4a21f485a71d5 to your computer and use it in GitHub Desktop.
AWS CredentialProviderChain example in aws-sdk of NodeJS
var AWS = require('aws-sdk');
var chain = new AWS.CredentialProviderChain();
var credentials
AWS.CredentialProviderChain.defaultProviders = [
function () { return new AWS.EnvironmentCredentials('AWS'); },
function () { return new AWS.EnvironmentCredentials('AMAZON'); },
function () { return new AWS.SharedIniFileCredentials({profile: 'my_profile_name'}); },
function () { return new AWS.EC2MetadataCredentials(); }
]
chain.resolve((err, cred)=>{
AWS.config.credentials = credentials = cred;
});
AWS.config.update({region: 'us-west-2' });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment