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": "",