Skip to content

Commit

Permalink
Merge pull request #1 from phamoramic/remove_metadata_query
Browse files Browse the repository at this point in the history
Remove metadata query when role === "any"
  • Loading branch information
phamoramic authored Dec 15, 2017
2 parents 5990fda + 7e4d8ef commit 378bbbf
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions lib/aws-cloudwatch-statsd-backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,16 @@ function CloudwatchBackend(startupTime, config, emitter) {
}

// if iamRole is set attempt to fetch credentials from the Metadata Service
if (this.config.iamRole) {
if (this.config.iamRole == 'any') {
// If the iamRole is set to any, then attempt to fetch any available credentials
ms = new AWS.EC2MetadataCredentials();
ms.refresh(function(err) {
if (err) { console.log('Failed to fetch IAM role credentials: ' + err); }
self.config.credentials = ms;
setEmitter();
});
} else {
// however if it's set to specify a role, query it specifically.
ms = new AWS.MetadataService();
ms.request('/latest/meta-data/iam/security-credentials/' + this.config.iamRole, function(err, rdata) {
var data = JSON.parse(rdata);

if (err) { console.log('Failed to fetch IAM role credentials: ' + err); }
self.config.credentials = new AWS.Credentials(data.AccessKeyId, data.SecretAccessKey, data.Token);
setEmitter();
});
}
if (this.config.iamRole && this.config.iamRole !== 'any') {
// if it's set to specify a role, query it specifically.
ms = new AWS.MetadataService();
ms.request('/latest/meta-data/iam/security-credentials/' + this.config.iamRole, function(err, rdata) {
var data = JSON.parse(rdata);

if (err) { console.log('Failed to fetch IAM role credentials: ' + err); }
self.config.credentials = new AWS.Credentials(data.AccessKeyId, data.SecretAccessKey, data.Token);
setEmitter();
});
} else {
setEmitter();
}
Expand Down

0 comments on commit 378bbbf

Please sign in to comment.