serverless-log-forwarding
Advanced tools
Comparing version 1.1.6 to 1.1.8
24
index.js
@@ -58,2 +58,3 @@ 'use strict'; | ||
const filterPattern = service.custom.logForwarding.filterPattern || ''; | ||
const normalizedFilterID = !(service.custom.logForwarding.normalizedFilterID === false); | ||
// Get options and parameters to make resources object | ||
@@ -78,3 +79,7 @@ const arn = service.custom.logForwarding.destinationARN; | ||
/* merge new SubscriptionFilter with current resources object */ | ||
const subscriptionFilter = this.makeSubscriptionFilter(arn, functions[i], filterPattern); | ||
const subscriptionFilter = this.makeSubscriptionFilter(functions[i], { | ||
arn, | ||
filterPattern, | ||
normalizedFilterID, | ||
}); | ||
_.extend(resourceObj, subscriptionFilter); | ||
@@ -88,11 +93,16 @@ } | ||
* Makes a Subscription Filter object for given function name | ||
* @param {String} arn arn of the lambda to forward to | ||
* @param {String} functionName name of function to make SubscriptionFilter for | ||
* @param {String} filterPattern filter pattern for the Subscription | ||
* @param {Object} options with | ||
* arn: arn of the lambda to forward to | ||
* filterPattern: filter pattern for the Subscription | ||
* normalizedFilterID: whether to use normalized FuncName as filter ID | ||
* @return {Object} SubscriptionFilter | ||
*/ | ||
makeSubscriptionFilter(arn, functionName, filterPattern) { | ||
makeSubscriptionFilter(functionName, options) { | ||
const functionObject = this.serverless.service.getFunction(functionName); | ||
const logGroupName = this.provider.naming.getLogGroupName(functionObject.name); | ||
const filterLogicalId = `SubscriptionFilter${this.provider.naming.getNormalizedFunctionName(functionName)}`; | ||
const filterName = options.normalizedFilterID ? | ||
this.provider.naming.getNormalizedFunctionName(functionName) | ||
: functionName; | ||
const filterLogicalId = `SubscriptionFilter${filterName}`; | ||
const functionLogGroupId = this.provider.naming.getLogGroupLogicalId(functionName); | ||
@@ -103,4 +113,4 @@ const filter = {}; | ||
Properties: { | ||
DestinationArn: arn, | ||
FilterPattern: filterPattern, | ||
DestinationArn: options.arn, | ||
FilterPattern: options.filterPattern, | ||
LogGroupName: logGroupName, | ||
@@ -107,0 +117,0 @@ }, |
{ | ||
"name": "serverless-log-forwarding", | ||
"version": "1.1.6", | ||
"version": "1.1.8", | ||
"description": "a serverless plugin to forward logs to given lambda function", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -39,2 +39,3 @@ # serverless-log-forwarding | ||
filterPattern: '[filter pattern for logs that are sent to Lambda function]' | ||
normalizedFilterID: true # whether to use normalized function name as filter ID | ||
stages: | ||
@@ -41,0 +42,0 @@ - '[name of the stage to apply log forwarding]' |
@@ -15,2 +15,3 @@ const chai = require('chai'); | ||
filterPattern: 'Test Pattern', | ||
normalizedFilterID: false, | ||
}; | ||
@@ -262,3 +263,3 @@ const correctConfigWithStageFilter = { | ||
}, | ||
SubscriptionFilterTestFunctionOne: { | ||
SubscriptionFiltertestFunctionOne: { | ||
Type: 'AWS::Logs::SubscriptionFilter', | ||
@@ -275,3 +276,3 @@ Properties: { | ||
}, | ||
SubscriptionFilterTestFunctionTwo: { | ||
SubscriptionFiltertestFunctionTwo: { | ||
Type: 'AWS::Logs::SubscriptionFilter', | ||
@@ -278,0 +279,0 @@ Properties: { |
Sorry, the diff of this file is too big to display
186651
12
5249
73