Skip to content

Commit

Permalink
🐛 Fix CloudWatchLogs filter pattern syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
tsub committed Dec 5, 2016
1 parent b39d751 commit eaffd3f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -26,7 +26,7 @@ functions:
- subscriptionFilter:
stage: prod
logGroupName: /cloud-trail
filterPattern: "{ $.errorMessage != '' }"
filterPattern: '{ $.errorMessage != "" }'
```

Supports also multiple subscription filter.
Expand All @@ -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:
Expand All @@ -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

Expand Down
6 changes: 5 additions & 1 deletion src/index.js
Expand Up @@ -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 = `
{
Expand Down Expand Up @@ -194,6 +194,10 @@ class ServerlessPluginSubscriptionFilter {

return `${normalizedFunctionName}LambdaPermission${normalizedLogGroupName}`;
}

escapeDoubleQuote(str) {
return str.replace(/\"/g, '\\"');
}
}

module.exports = ServerlessPluginSubscriptionFilter;

0 comments on commit eaffd3f

Please sign in to comment.