From 63e6a653eb6097518ce54fd71a000c44775a94f5 Mon Sep 17 00:00:00 2001 From: Jan Bobisud Date: Fri, 28 Oct 2016 12:43:57 +0200 Subject: [PATCH] Allow to set AWS region --- README.md | 3 ++- index.js | 15 ++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 31f1646..b3fc53b 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,8 @@ const S3Notifier = require('fastboot-s3-notifier'); let notifier = new S3Notifier({ bucket: S3_BUCKET, - key: S3_KEY + key: S3_KEY, + region: AWS_REGION // optional }); let server = new FastBootAppServer({ diff --git a/index.js b/index.js index 92ca40e..9843d8e 100644 --- a/index.js +++ b/index.js @@ -4,11 +4,6 @@ const AWS = require('aws-sdk'); const DEFAULT_POLL_TIME = 3 * 1000; -const s3 = new AWS.S3({ - apiVersion: '2006-03-01', - signatureVersion: 'v4' -}); - class S3Notifier { constructor(options) { this.ui = options.ui; @@ -20,6 +15,12 @@ class S3Notifier { Bucket: this.bucket, Key: this.key }; + + this.s3 = new AWS.S3({ + apiVersion: '2006-03-01', + signatureVersion: 'v4', + region: options.region + }); } subscribe(notify) { @@ -30,7 +31,7 @@ class S3Notifier { } getCurrentLastModified() { - return s3.headObject(this.params).promise() + return this.s3.headObject(this.params).promise() .then(data => { this.lastModified = data.LastModified; }) @@ -46,7 +47,7 @@ class S3Notifier { } poll() { - s3.headObject(this.params).promise() + this.s3.headObject(this.params).promise() .then(data => { this.compareLastModifieds(data.LastModified); this.schedulePoll();