diff --git a/README.md b/README.md index 97d90cd..f07da86 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ functions: - subscriptionFilter: stage: prod logGroupName: /cloud-trail - filterPattern: "{ $.errorMessage != '' }" + filterPattern: '{ $.errorMessage != "" }' ``` Supports also multiple subscription filter. @@ -39,11 +39,11 @@ functions: - subscriptionFilter: stage: prod logGroupName: /cloud-trail - filterPattern: "{ $.errorMessage != '' }" + filterPattern: '{ $.errorMessage != "" }' - subscriptionFilter: stage: prod logGroupName: /my-log-group - filterPattern: "{ $.errorMessage != '' }" + filterPattern: '{ $.errorMessage != "" }' goodbye: handler: handler.goodbye events: @@ -59,7 +59,7 @@ functions: |:---:|:---:| |stage|The deployment stage with serverless. Because only one subscription filter can be set for one LogGroup.| |logGroupName|The log group to associate with the subscription filter. | -|filterPattern|The filtering expressions that restrict what gets delivered to the destination AWS resource. Sorry, if you want to use "{ $.xxx = yyy }" syntax, then surround ""(double quote).| +|filterPattern|The filtering expressions that restrict what gets delivered to the destination AWS resource. Sorry, if you want to use '{ $.xxx = "yyy" }' syntax, then surround the whole in ''(single quote).| ## Future supports diff --git a/src/index.js b/src/index.js index b11d42a..c1a8e75 100644 --- a/src/index.js +++ b/src/index.js @@ -107,7 +107,7 @@ class ServerlessPluginSubscriptionFilter { return new Promise((resolve, _reject) => { const lambdaLogicalId = this.provider.naming.getLambdaLogicalId(functionName); const lambdaPermissionLogicalId = this.getLambdaPermissionLogicalId(functionName, setting.logGroupName); - const filterPattern = setting.filterPattern; + const filterPattern = this.escapeDoubleQuote(setting.filterPattern); const logGroupName = setting.logGroupName; const subscriptionFilterTemplate = ` { @@ -194,6 +194,10 @@ class ServerlessPluginSubscriptionFilter { return `${normalizedFunctionName}LambdaPermission${normalizedLogGroupName}`; } + + escapeDoubleQuote(str) { + return str.replace(/\"/g, '\\"'); + } } module.exports = ServerlessPluginSubscriptionFilter;