From 7b264d33d772ab181459c1fa82bd4b2c59bbbeef Mon Sep 17 00:00:00 2001 From: "Eslam A. Hefnawy" Date: Sat, 6 Feb 2016 12:01:11 +0700 Subject: [PATCH] final event sources cleanup --- lib/actions/EventDeployS3Lambda.js | 13 ++++++++++--- lib/actions/EventDeploySNSLambda.js | 13 +++++++++++-- lib/actions/EventDeployScheduledLambda.js | 14 ++++++++++---- lib/actions/EventDeployStreamLambda.js | 12 ++++++++++++ 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/lib/actions/EventDeployS3Lambda.js b/lib/actions/EventDeployS3Lambda.js index c39ea9893..d5d1d2262 100644 --- a/lib/actions/EventDeployS3Lambda.js +++ b/lib/actions/EventDeployS3Lambda.js @@ -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); }) } diff --git a/lib/actions/EventDeploySNSLambda.js b/lib/actions/EventDeploySNSLambda.js index 08b130a1e..79f6d663d 100644 --- a/lib/actions/EventDeploySNSLambda.js +++ b/lib/actions/EventDeploySNSLambda.js @@ -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); }); } diff --git a/lib/actions/EventDeployScheduledLambda.js b/lib/actions/EventDeployScheduledLambda.js index 2b2b2de90..be0443176 100644 --- a/lib/actions/EventDeployScheduledLambda.js +++ b/lib/actions/EventDeployScheduledLambda.js @@ -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); }); } diff --git a/lib/actions/EventDeployStreamLambda.js b/lib/actions/EventDeployStreamLambda.js index 8f449ae24..e547d3195 100644 --- a/lib/actions/EventDeployStreamLambda.js +++ b/lib/actions/EventDeployStreamLambda.js @@ -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