Skip to content

Commit

Permalink
use internal request method instead of creating sns, cloudwatch and c…
Browse files Browse the repository at this point in the history
…loudwatch logs objects

fixes #16
  • Loading branch information
martinlindenberg committed Jul 13, 2016
1 parent 752e9e9 commit 87f9c63
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 35 deletions.
43 changes: 9 additions & 34 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ module.exports = function(S) {
let _this = this;

_this.stage = evt.options.stage;
_this.region = region;
_this._initAws(region);

if (S.cli.action != 'deploy' || (S.cli.context != 'function' && S.cli.context != 'dash'))
Expand Down Expand Up @@ -162,8 +163,9 @@ module.exports = function(S) {
if (alertNamesProcessed.indexOf(alertConfig.AlarmName) === -1) {
alertNamesProcessed.push(alertConfig.AlarmName);
alertActions.push(
_this.cloudWatch.putMetricAlarmAsync(alertConfig)
_this.aws.request('CloudWatch', 'putMetricAlarm', alertConfig, _this.stage, _this.region)
);

} else
console.log('skipping \''+alertConfig.AlarmName+'\', alerting.json has overriding settings.')
}
Expand Down Expand Up @@ -205,7 +207,7 @@ module.exports = function(S) {
}
});
metricFilterActions.push(
_this.cloudWatchLogs.putMetricFilterAsync(alertContent.metricFilters[metricfilter])
_this.aws.request('CloudWatchLogs', 'putMetricFilter', alertContent.metricFilters[metricfilter], _this.stage, _this.region)
);
}
}
Expand Down Expand Up @@ -239,7 +241,7 @@ module.exports = function(S) {
alertContent.subscriptionFilters[subscriptionFilter].filterName = subscriptionFilter;
alertContent.subscriptionFilters[subscriptionFilter].logGroupName = logGroupName;
subscriptionFilterActions.push(
_this.cloudWatchLogs.putSubscriptionFilterAsync(alertContent.subscriptionFilters[subscriptionFilter])
_this.aws.request('CloudWatchLogs', 'putSubscriptionFilter', alertContent.subscriptionFilters[subscriptionFilter], _this.stage, _this.region)
);
}
}
Expand All @@ -258,7 +260,7 @@ module.exports = function(S) {
var _this = this;
_this.topics = topics;

return _this.sns.listTopicsAsync()
return _this.aws.request('SNS', 'listTopics', {}, _this.stage, _this.region)
.then(function(topicListResult){
var _this = this;
//create fast checkable topiclist['topic1'] = 'topic1'
Expand All @@ -274,9 +276,7 @@ module.exports = function(S) {
for (var i in this.topics) {
if (!topicList[i]) {
console.log('topic ' + i + ' does not exist. it will be created now');
_this.sns.createTopicAsync({
'Name': i
})
_this.aws.request('SNS', 'createTopic', {'Name': i}, _this.stage, _this.region)
.then(function(){
console.log('topic created');
})
Expand All @@ -298,33 +298,8 @@ module.exports = function(S) {
* @return void
*/
_initAws (region) {
let _this = this,
credentials = S.getProvider('aws').getCredentials(_this.stage, region);

_this.cloudWatch = new AWS.CloudWatch({
region: region,
accessKeyId: credentials.accessKeyId,
secretAccessKey: credentials.secretAccessKey,
sessionToken: credentials.sessionToken
});

_this.cloudWatchLogs = new AWS.CloudWatchLogs({
region: region,
accessKeyId: credentials.accessKeyId,
secretAccessKey: credentials.secretAccessKey,
sessionToken: credentials.sessionToken
});

_this.sns = new AWS.SNS({
region: region,
accessKeyId: credentials.accessKeyId,
secretAccessKey: credentials.secretAccessKey,
sessionToken: credentials.sessionToken
});

BbPromise.promisifyAll(_this.cloudWatch);
BbPromise.promisifyAll(_this.cloudWatchLogs);
BbPromise.promisifyAll(_this.sns);
let _this = this;
_this.aws = S.getProvider('aws');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "serverless-plugin-alerting",
"version": "0.5.11",
"version": "0.5.12",
"engines": {
"node": ">=4.0"
},
Expand Down

0 comments on commit 87f9c63

Please sign in to comment.