From a300dad1d8a546a6741cd72b101bd7ebfc793493 Mon Sep 17 00:00:00 2001 From: "Eslam A. Hefnawy" Date: Tue, 15 Dec 2015 21:11:14 +0200 Subject: [PATCH] added EventSource support --- lib/actions/CreateEventSourceLambdaNodejs.js | 24 ++++++++++---------- lib/actions/FunctionDeploy.js | 2 +- lib/templates/s-function.json | 1 + 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/actions/CreateEventSourceLambdaNodejs.js b/lib/actions/CreateEventSourceLambdaNodejs.js index 96814cf3b..6f5de2e53 100644 --- a/lib/actions/CreateEventSourceLambdaNodejs.js +++ b/lib/actions/CreateEventSourceLambdaNodejs.js @@ -6,12 +6,8 @@ const SPlugin = require('../ServerlessPlugin'), SError = require('../ServerlessError'), - SUtils = require('../utils/index'), SCli = require('../utils/cli'), - BbPromise = require('bluebird'), - path = require('path'), - chalk = require('chalk'), - context = require('../utils/context'); + BbPromise = require('bluebird'); class CreateEventSourceLambdaNodejs extends SPlugin { @@ -42,6 +38,8 @@ class CreateEventSourceLambdaNodejs extends SPlugin { let _this = this; + if (!evt.function.eventSourceArn) return evt; + // Load AWS Service Instances let awsConfig = { region: evt.region.region, @@ -49,30 +47,32 @@ class CreateEventSourceLambdaNodejs extends SPlugin { secretAccessKey: _this.S._awsAdminSecretKey, }; - _this.Lambda = require('../utils/aws/Lambda')(awsConfig); + _this.Lambda = require('../utils/aws/Lambda')(awsConfig); let params = { FunctionName: _this.Lambda.sGetLambdaName(_this.S._projectJson, evt.function), - EventSourceArn: evt.function.eventSource, + EventSourceArn: evt.function.eventSourceArn, StartingPosition: 'LATEST' }; return _this.Lambda.createEventSourceMappingPromised(params) .then(function(data) { - SCli.log('Created Event Source for Lambda: ' + evt.function.name); - evt.function.EventSourceArn = data.EventSourceArn; + SCli.log('Created event source for lambda: ' + evt.function.name); + evt.function.EventSourceUUID = data.UUID; return evt; }) .catch(function(e) { - console.log('error') if (e.code === 'ResourceConflictException') { - SCli.log('Event source already exists: ' + evt.function.name); + + SCli.log('Event source already exists for lambda: ' + evt.function.name); + return evt; } else { - throw new SError(`Error setting lambda event source: ` + e); + return evt; + //throw new SError(`Error setting lambda event source: ` + e); } }) diff --git a/lib/actions/FunctionDeploy.js b/lib/actions/FunctionDeploy.js index da62911a0..f30bc81c5 100644 --- a/lib/actions/FunctionDeploy.js +++ b/lib/actions/FunctionDeploy.js @@ -300,7 +300,7 @@ class FunctionDeploy extends SPlugin { return _this.S.actions.codePackageLambdaNodejs(evtClone) .bind(_this) .then(_this.S.actions.codeDeployLambdaNodejs) - //.then(_this.S.actions.createEventSourceLambdaNodejs) + .then(_this.S.actions.createEventSourceLambdaNodejs) .then(function(evtCloneProcessed) { // Add Function and Region diff --git a/lib/templates/s-function.json b/lib/templates/s-function.json index 2ee621bbf..83beeb57f 100644 --- a/lib/templates/s-function.json +++ b/lib/templates/s-function.json @@ -8,6 +8,7 @@ "handler": "", "timeout": 6, "memorySize": 1024, + "eventSourceArn": "", "endpoints": [ { "path": "",