added EventSource support

This commit is contained in:
Eslam A. Hefnawy 2015-12-15 21:11:14 +02:00
parent a8bf57ab28
commit a300dad1d8
3 changed files with 14 additions and 13 deletions

View File

@ -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);
}
})

View File

@ -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

View File

@ -8,6 +8,7 @@
"handler": "",
"timeout": 6,
"memorySize": 1024,
"eventSourceArn": "",
"endpoints": [
{
"path": "",