Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Multi-region support. #6

Merged
merged 1 commit into from about 1 year ago

2 participants

Andrew Canaday Frank LoVecchio
Andrew Canaday

Hello again,

I've got another change for you to review. I added an additional (optional) environment variable 'AWS_CLOUDWATCH_HOST' which can be used to specify a CloudWatch endpoint in a region other than us-east-1.

Thanks,
-Andrew

Andrew Canaday Look for env var 'AWS_CLOUDWATCH_HOST' and use that instead of defaul…
…t us-east-1 host, if specified.

Otherwise, default to us-east-1.
4d1a53c
Frank LoVecchio

Thanks for adding - when I wrote the library, there was only one endpoint available!

Frank LoVecchio franklovecchio merged commit 1edbd40 into from February 22, 2013
Frank LoVecchio franklovecchio closed this February 22, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Feb 22, 2013
Andrew Canaday Look for env var 'AWS_CLOUDWATCH_HOST' and use that instead of defaul…
…t us-east-1 host, if specified.

Otherwise, default to us-east-1.
4d1a53c
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 19 additions and 3 deletions. Show diff stats Hide diff stats

  1. 22  index.js
22  index.js
@@ -6,13 +6,21 @@ var crypto = require('crypto'),
6 6
 var AmazonCloudwatchClient = function () {};
7 7
 
8 8
 AmazonCloudwatchClient.prototype.configureHttp = function (requestMethod, query) {
  9
+  // Use the user-specified AWS host, defaulting to us-east-1, if absent.
  10
+  if( process.env['AWS_CLOUDWATCH_HOST'] != null ) {
  11
+    var cloudwatchHost = process.env['AWS_CLOUDWATCH_HOST']
  12
+  }
  13
+  else {
  14
+    var cloudwatchHost = 'monitoring.us-east-1.amazonaws.com';
  15
+  };
  16
+
9 17
   var options = {
10  
-    host: 'monitoring.amazonaws.com',
  18
+    host: cloudwatchHost,
11 19
     port: 80,
12 20
     path: query,
13 21
     method: requestMethod,
14 22
     headers: {
15  
-      'Host': 'monitoring.us-east-1.amazonaws.com',
  23
+      'Host': cloudwatchHost,
16 24
       'Content-Length': 0
17 25
     }
18 26
   };
@@ -37,6 +45,14 @@ AmazonCloudwatchClient.prototype.timestampBuilder = function () {
37 45
 };
38 46
 
39 47
 AmazonCloudwatchClient.prototype.queryBuilder = function (command, parameters) {
  48
+  // Use the user-specified AWS host, defaulting to us-east-1, if absent.
  49
+  if( process.env['AWS_CLOUDWATCH_HOST'] != null ) {
  50
+    var cloudwatchHost = process.env['AWS_CLOUDWATCH_HOST']
  51
+  }
  52
+  else {
  53
+    var cloudwatchHost = 'monitoring.us-east-1.amazonaws.com';
  54
+  };
  55
+
40 56
   var map = {
41 57
     AWSAccessKeyId: process.env['AWS_ACCESS_KEY_ID'],
42 58
     Action: command,
@@ -66,7 +82,7 @@ AmazonCloudwatchClient.prototype.queryBuilder = function (command, parameters) {
66 82
     var name = names[_i];
67 83
     query.push(this.escape(name) + '=' + this.escape(parameters[name]));
68 84
   }
69  
-  var toSign = 'GET\n' + ('monitoring.us-east-1.amazonaws.com\n') + '/\n' + query.join('&');
  85
+  var toSign = 'GET\n' + (cloudwatchHost + '\n') + '/\n' + query.join('&');
70 86
   var hmac = crypto.createHmac('sha256', process.env['AWS_SECRET_ACCESS_KEY']);
71 87
   hmac.update(toSign);
72 88
   var digest = this.escape(hmac.digest('base64'));
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.