mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
final event sources cleanup
This commit is contained in:
parent
e0eb0803d8
commit
7b264d33d7
@ -1,6 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* EventDeployS3Lambda:
|
||||
* Deploys an S3 based event sources.
|
||||
*
|
||||
* Options:
|
||||
* - stage: stage to deploy event to
|
||||
* - region: region to deploy event to
|
||||
* - path: event path
|
||||
*/
|
||||
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
@ -39,7 +46,6 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
let _this = this;
|
||||
_this.evt = evt;
|
||||
|
||||
// Validate required properties
|
||||
if (!_this.evt.options.stage || !_this.evt.options.region || !_this.evt.options.path) {
|
||||
return BbPromise.reject(new SError(`Missing stage, region or path.`));
|
||||
}
|
||||
@ -56,8 +62,6 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
|
||||
_this.S3 = require('../utils/aws/S3')(awsConfig);
|
||||
|
||||
// the AWS method creates or updates the notification configuration,
|
||||
// so we don't need to check if we're updating or creating
|
||||
let params = {
|
||||
Bucket: populatedEvent.config.bucket,
|
||||
NotificationConfiguration: {
|
||||
@ -72,6 +76,9 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
|
||||
return _this.S3.putBucketNotificationConfigurationPromised(params)
|
||||
.then(function(data) {
|
||||
|
||||
SUtils.sDebug(`Put notification configuration for bucket ${populatedEvent.config.bucket} and lambda ${lambdaArn}`);
|
||||
|
||||
return BbPromise.resolve(data);
|
||||
})
|
||||
}
|
||||
|
||||
@ -1,6 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* EventDeploySNSLambda:
|
||||
* Deploys an SNS based event sources. Subscribes a lambda to an SNS topic.
|
||||
*
|
||||
* Options:
|
||||
* - stage: stage to deploy event to
|
||||
* - region: region to deploy event to
|
||||
* - path: event path
|
||||
*/
|
||||
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
@ -32,14 +39,13 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Code Package Lambda
|
||||
* Event Deploy SNS Lambda
|
||||
*/
|
||||
|
||||
eventDeploySNSLambda(evt) {
|
||||
let _this = this;
|
||||
_this.evt = evt;
|
||||
|
||||
// Validate required properties
|
||||
if (!_this.evt.options.stage || !_this.evt.options.region || !_this.evt.options.path) {
|
||||
return BbPromise.reject(new SError(`Missing stage, region or path.`));
|
||||
}
|
||||
@ -65,6 +71,9 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
|
||||
return _this.SNS.subscribePromised(params)
|
||||
.then(function(data){
|
||||
|
||||
SUtils.sDebug(`Subscription to SNS topic ${populatedEvent.config.topicArn} added for lambda ${lambdaArn}`);
|
||||
|
||||
return BbPromise.resolve(data);
|
||||
});
|
||||
}
|
||||
|
||||
@ -12,9 +12,10 @@
|
||||
|
||||
module.exports = function (SPlugin, serverlessPath) {
|
||||
|
||||
const path = require('path'),
|
||||
SError = require(path.join(serverlessPath, 'ServerlessError')),
|
||||
BbPromise = require('bluebird');
|
||||
const path = require('path'),
|
||||
SError = require(path.join(serverlessPath, 'ServerlessError')),
|
||||
SUtils = require(path.join(serverlessPath, 'utils/index')),
|
||||
BbPromise = require('bluebird');
|
||||
|
||||
|
||||
class EventDeployScheduledLambda extends SPlugin {
|
||||
@ -45,7 +46,6 @@ module.exports = function (SPlugin, serverlessPath) {
|
||||
let _this = this;
|
||||
_this.evt = evt;
|
||||
|
||||
// Validate required properties
|
||||
if (!_this.evt.options.stage || !_this.evt.options.region || !_this.evt.options.path) {
|
||||
return BbPromise.reject(new SError(`Missing stage, region or path.`));
|
||||
}
|
||||
@ -73,6 +73,9 @@ module.exports = function (SPlugin, serverlessPath) {
|
||||
|
||||
return _this.CloudWatchEvents.putRuleAsync(params)
|
||||
.then(function (data) {
|
||||
|
||||
SUtils.sDebug(`Put CloudWatchEvents Rule ${pathName}`);
|
||||
|
||||
let params = {
|
||||
Rule: pathName,
|
||||
Targets: [
|
||||
@ -85,6 +88,9 @@ module.exports = function (SPlugin, serverlessPath) {
|
||||
return _this.CloudWatchEvents.putTargetsAsync(params);
|
||||
})
|
||||
.then(function (data) {
|
||||
|
||||
SUtils.sDebug(`Set lambda ${lambdaArn} as target for rule ${pathName} for lambda ${pathName}`);
|
||||
|
||||
return BbPromise.resolve(data);
|
||||
});
|
||||
}
|
||||
|
||||
@ -1,6 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
|
||||
/**
|
||||
* EventDeployStreamLambda:
|
||||
* Deploys a Stream based event sources (dynamoDB & Kinesis).
|
||||
*
|
||||
* Options:
|
||||
* - stage: stage to deploy event to
|
||||
* - region: region to deploy event to
|
||||
* - path: event path
|
||||
*/
|
||||
|
||||
module.exports = function(SPlugin, serverlessPath) {
|
||||
@ -74,16 +82,20 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
|
||||
return _this.Lambda.updateEventSourceMappingPromised(params)
|
||||
.then(function (data) {
|
||||
|
||||
SUtils.sDebug(`updated stream event source ${populatedEvent.config.streamArn} for lambda ${lambdaArn}`);
|
||||
|
||||
return BbPromise.resolve(data);
|
||||
});
|
||||
|
||||
} else {
|
||||
|
||||
params.EventSourceArn = populatedEvent.config.streamArn;
|
||||
params.StartingPosition = populatedEvent.config.startingPosition;
|
||||
|
||||
return _this.Lambda.createEventSourceMappingPromised(params)
|
||||
.then(function (data) {
|
||||
|
||||
SUtils.sDebug(`Created stream event source ${populatedEvent.config.streamArn} for lambda ${lambdaArn}`);
|
||||
|
||||
// save UUID
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user