final event sources cleanup

This commit is contained in:
Eslam A. Hefnawy 2016-02-06 12:01:11 +07:00
parent e0eb0803d8
commit 7b264d33d7
4 changed files with 43 additions and 9 deletions

View File

@ -1,6 +1,13 @@
'use strict';
/**
* EventDeployS3Lambda:
* Deploys an S3 based event sources.
*
* Options:
* - stage: stage to deploy event to
* - region: region to deploy event to
* - path: event path
*/
module.exports = function(SPlugin, serverlessPath) {
@ -39,7 +46,6 @@ module.exports = function(SPlugin, serverlessPath) {
let _this = this;
_this.evt = evt;
// Validate required properties
if (!_this.evt.options.stage || !_this.evt.options.region || !_this.evt.options.path) {
return BbPromise.reject(new SError(`Missing stage, region or path.`));
}
@ -56,8 +62,6 @@ module.exports = function(SPlugin, serverlessPath) {
_this.S3 = require('../utils/aws/S3')(awsConfig);
// the AWS method creates or updates the notification configuration,
// so we don't need to check if we're updating or creating
let params = {
Bucket: populatedEvent.config.bucket,
NotificationConfiguration: {
@ -72,6 +76,9 @@ module.exports = function(SPlugin, serverlessPath) {
return _this.S3.putBucketNotificationConfigurationPromised(params)
.then(function(data) {
SUtils.sDebug(`Put notification configuration for bucket ${populatedEvent.config.bucket} and lambda ${lambdaArn}`);
return BbPromise.resolve(data);
})
}

View File

@ -1,6 +1,13 @@
'use strict';
/**
* EventDeploySNSLambda:
* Deploys an SNS based event sources. Subscribes a lambda to an SNS topic.
*
* Options:
* - stage: stage to deploy event to
* - region: region to deploy event to
* - path: event path
*/
module.exports = function(SPlugin, serverlessPath) {
@ -32,14 +39,13 @@ module.exports = function(SPlugin, serverlessPath) {
}
/**
* Code Package Lambda
* Event Deploy SNS Lambda
*/
eventDeploySNSLambda(evt) {
let _this = this;
_this.evt = evt;
// Validate required properties
if (!_this.evt.options.stage || !_this.evt.options.region || !_this.evt.options.path) {
return BbPromise.reject(new SError(`Missing stage, region or path.`));
}
@ -65,6 +71,9 @@ module.exports = function(SPlugin, serverlessPath) {
return _this.SNS.subscribePromised(params)
.then(function(data){
SUtils.sDebug(`Subscription to SNS topic ${populatedEvent.config.topicArn} added for lambda ${lambdaArn}`);
return BbPromise.resolve(data);
});
}

View File

@ -12,9 +12,10 @@
module.exports = function (SPlugin, serverlessPath) {
const path = require('path'),
SError = require(path.join(serverlessPath, 'ServerlessError')),
BbPromise = require('bluebird');
const path = require('path'),
SError = require(path.join(serverlessPath, 'ServerlessError')),
SUtils = require(path.join(serverlessPath, 'utils/index')),
BbPromise = require('bluebird');
class EventDeployScheduledLambda extends SPlugin {
@ -45,7 +46,6 @@ module.exports = function (SPlugin, serverlessPath) {
let _this = this;
_this.evt = evt;
// Validate required properties
if (!_this.evt.options.stage || !_this.evt.options.region || !_this.evt.options.path) {
return BbPromise.reject(new SError(`Missing stage, region or path.`));
}
@ -73,6 +73,9 @@ module.exports = function (SPlugin, serverlessPath) {
return _this.CloudWatchEvents.putRuleAsync(params)
.then(function (data) {
SUtils.sDebug(`Put CloudWatchEvents Rule ${pathName}`);
let params = {
Rule: pathName,
Targets: [
@ -85,6 +88,9 @@ module.exports = function (SPlugin, serverlessPath) {
return _this.CloudWatchEvents.putTargetsAsync(params);
})
.then(function (data) {
SUtils.sDebug(`Set lambda ${lambdaArn} as target for rule ${pathName} for lambda ${pathName}`);
return BbPromise.resolve(data);
});
}

View File

@ -1,6 +1,14 @@
'use strict';
/**
* EventDeployStreamLambda:
* Deploys a Stream based event sources (dynamoDB & Kinesis).
*
* Options:
* - stage: stage to deploy event to
* - region: region to deploy event to
* - path: event path
*/
module.exports = function(SPlugin, serverlessPath) {
@ -74,16 +82,20 @@ module.exports = function(SPlugin, serverlessPath) {
return _this.Lambda.updateEventSourceMappingPromised(params)
.then(function (data) {
SUtils.sDebug(`updated stream event source ${populatedEvent.config.streamArn} for lambda ${lambdaArn}`);
return BbPromise.resolve(data);
});
} else {
params.EventSourceArn = populatedEvent.config.streamArn;
params.StartingPosition = populatedEvent.config.startingPosition;
return _this.Lambda.createEventSourceMappingPromised(params)
.then(function (data) {
SUtils.sDebug(`Created stream event source ${populatedEvent.config.streamArn} for lambda ${lambdaArn}`);
// save UUID