Skip to content

aws-logs: Allow JSON filter patterns to use regex by removing automatic double quotes around pattern strings #30451

@sobesim

Description

@sobesim

Describe the feature

FilterPattern.stringValue should allow the user to specify if the value input field is a regex string or not.

Use Case

According to CloudWatch filter pattern documentation, regex expressions must be surrounded by %.

I'm trying to use cdk's FilterPattern.stringValue to match a json document.

CDK automatically adds double quotes in the final filter pattern, which prevents Cloudwatch from recognizing any string as a regex pattern. For example:

  • Correct: { $.foo = %bar% }
  • Incorrect: { $.foo = “%bar%” }, what is produced by CDK and does not match the document : {“foo”:“bar”}

Proposed Solution

Reason for this behavior may be this line: https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-logs/lib/pattern.ts#L399. Perhaps we need another input to stringValue that allows the user to specify if the input string is a regex pattern or not.

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.144.0

Environment details (OS name and version, etc.)

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-logsRelated to Amazon CloudWatch Logseffort/mediumMedium work item – several days of effortfeature-requestA feature should be added or improved.p2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions