mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
added EventSource support
This commit is contained in:
parent
a8bf57ab28
commit
a300dad1d8
@ -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);
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
"handler": "",
|
||||
"timeout": 6,
|
||||
"memorySize": 1024,
|
||||
"eventSourceArn": "",
|
||||
"endpoints": [
|
||||
{
|
||||
"path": "",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user