Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove metadata query when role === "any" #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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