From 7e4d8ef946279d5b339cc249205f52eadd1ec49d Mon Sep 17 00:00:00 2001 From: Yousef Date: Wed, 29 Mar 2017 09:52:35 +0200 Subject: [PATCH] Remove metadata query when role === "any" --- lib/aws-cloudwatch-statsd-backend.js | 30 ++++++++++------------------ 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/lib/aws-cloudwatch-statsd-backend.js b/lib/aws-cloudwatch-statsd-backend.js index f0de42f..0f5dbf0 100644 --- a/lib/aws-cloudwatch-statsd-backend.js +++ b/lib/aws-cloudwatch-statsd-backend.js @@ -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(); }