mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
added event source array to functions
This commit is contained in:
parent
dc018aa3d4
commit
13f8df0da0
@ -36,6 +36,10 @@
|
||||
"path": "./actions/CodeDeployLambdaNodeJs.js",
|
||||
"config": {}
|
||||
},
|
||||
{
|
||||
"path": "./actions/CodeEventDeployLambda.js",
|
||||
"config": {}
|
||||
},
|
||||
{
|
||||
"path": "./actions/EndpointDeploy.js",
|
||||
"config": {}
|
||||
|
||||
@ -4,11 +4,17 @@
|
||||
* Action: FunctionRunLambdaNodeJs
|
||||
*/
|
||||
|
||||
|
||||
module.exports = function (SPlugin, serverlessPath) {
|
||||
const path = require('path'),
|
||||
SCli = require(path.join(serverlessPath, 'utils/cli')),
|
||||
|
||||
const SPlugin = require('../ServerlessPlugin'),
|
||||
SError = require('../ServerlessError'),
|
||||
SCli = require('../utils/cli'),
|
||||
async = require('async'),
|
||||
path = require('path'),
|
||||
BbPromise = require('bluebird');
|
||||
|
||||
|
||||
class CodeEventDeployLambda extends SPlugin {
|
||||
|
||||
constructor(S, config) {
|
||||
@ -34,11 +40,10 @@ module.exports = function (SPlugin, serverlessPath) {
|
||||
* Create Event Source for a Lambda Function
|
||||
*/
|
||||
|
||||
|
||||
codeEventDeployLambda(evt) {
|
||||
|
||||
let _this = this;
|
||||
|
||||
if (!evt.function.eventSourceArn) return evt;
|
||||
if (!evt.function.event[0].EventSourceArn) return evt;
|
||||
|
||||
// Load AWS Service Instances
|
||||
let awsConfig = {
|
||||
@ -47,37 +52,44 @@ module.exports = function (SPlugin, serverlessPath) {
|
||||
secretAccessKey: _this.S._awsAdminSecretKey,
|
||||
};
|
||||
|
||||
_this.Lambda = require('../utils/aws/Lambda')(awsConfig);
|
||||
|
||||
let params = {
|
||||
FunctionName: _this.Lambda.sGetLambdaName(_this.S._projectJson, evt.function),
|
||||
EventSourceArn: evt.function.eventSourceArn,
|
||||
StartingPosition: 'LATEST'
|
||||
};
|
||||
return new BbPromise(function (resolve, reject) {
|
||||
|
||||
|
||||
return _this.Lambda.createEventSourceMappingPromised(params)
|
||||
.then(function (data) {
|
||||
async.eachLimit(evt.function.event, 5, function (event, cb) {
|
||||
|
||||
SCli.log('Created event source for lambda: ' + evt.function.name);
|
||||
// Create new evt object for concurrent operations
|
||||
let params = event;
|
||||
|
||||
evt.function.EventSourceUUID = data.UUID;
|
||||
return evt;
|
||||
})
|
||||
.catch(function (e) {
|
||||
if (e.code === 'ResourceConflictException') {
|
||||
params.FunctionName = _this.Lambda.sGetLambdaName(_this.S._projectJson, evt.function);
|
||||
|
||||
SCli.log('Event source already exists for lambda: ' + evt.function.name);
|
||||
return _this.Lambda.createEventSourceMappingPromised(params)
|
||||
.then(function (data) {
|
||||
|
||||
SCli.sDebug(`Created event source ${event.EventSourceArn} for lambda ${evt.function.name}`);
|
||||
|
||||
evt.function.event.UUID = data.UUID;
|
||||
return cb();
|
||||
})
|
||||
.catch(function (e) {
|
||||
if (e.code === 'ResourceConflictException') {
|
||||
|
||||
SCli.sDebug(`Event source ${event.EventSourceArn} already exists for lambda ${evt.function.name}`);
|
||||
|
||||
return cb();
|
||||
} else {
|
||||
throw new SError(`Error setting lambda event source: ` + e);
|
||||
}
|
||||
})
|
||||
|
||||
}, function () {
|
||||
return resolve(evt);
|
||||
});
|
||||
});
|
||||
|
||||
return evt;
|
||||
} else {
|
||||
return evt;
|
||||
//throw new SError(`Error setting lambda event source: ` + e);
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return ( CodeEventDeployLambda );
|
||||
|
||||
@ -8,7 +8,14 @@
|
||||
"handler": "",
|
||||
"timeout": 6,
|
||||
"memorySize": 1024,
|
||||
"eventSourceArn": "",
|
||||
"event": [
|
||||
{
|
||||
"EventSourceArn": "",
|
||||
"StartingPosition": "TRIM_HORIZON",
|
||||
"BatchSize": 100,
|
||||
"Enabled": true
|
||||
}
|
||||
],
|
||||
"endpoints": [
|
||||
{
|
||||
"path": "",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user