node.js - Determine if aws-sdk is has global credentials configured -
from information provided in aws sdk config guide there multiple ways configure sdk:
- loaded iam roles amazon ec2 (if running on ec2),
- loaded shared credentials file (~/.aws/credentials),
- loaded environment variables,
- loaded json file on disk,
- hardcoded in application
is there way determine:
a) if sdk has global config (credentials) , b) how credentials/settings loaded/configured?
so appears can config's credentialprovider object credentialproviderchain. resolve() method returns instance of aws.credentials identify method used configuring credentials.
example follows:
aws.config.credentialprovider.resolve(function(err, credential) { if(credential !== null) { awscredential = credential.constructor.name; }) console.log("aws configured? ", awscredential ? 'yes'.green : 'no'.red); if(awscredential) { console.log(" provided by: ", awscredential); }
specifically noting returned credential
reveals classname via credential.constructor.name
.
edit: i've written post comparing use of callbacks promises achieve same goal - in case else encounters same question.
Comments
Post a Comment