FilterPattern Class
A collection of static methods to generate appropriate ILogPatterns.
Example
import * as destinations from 'aws-cdk-lib/aws-logs-destinations';
declare const fn: lambda.Function;
declare const logGroup: logs.LogGroup;
new logs.SubscriptionFilter(this, 'Subscription', {
logGroup,
destination: new destinations.LambdaDestination(fn),
filterPattern: logs.FilterPattern.allTerms("ERROR", "MainThread"),
filterName: 'ErrorInMainThread',
});
import aws_cdk.aws_logs_destinations as destinations
# fn: lambda.Function
# log_group: logs.LogGroup
logs.SubscriptionFilter(self, "Subscription",
log_group=log_group,
destination=destinations.LambdaDestination(fn),
filter_pattern=logs.FilterPattern.all_terms("ERROR", "MainThread"),
filter_name="ErrorInMainThread"
)
import software.amazon.awscdk.services.logs.destinations.*;
Function fn;
LogGroup logGroup;
SubscriptionFilter.Builder.create(this, "Subscription")
.logGroup(logGroup)
.destination(new LambdaDestination(fn))
.filterPattern(FilterPattern.allTerms("ERROR", "MainThread"))
.filterName("ErrorInMainThread")
.build();
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.Logs.Destinations;
Function fn;
LogGroup logGroup;
new SubscriptionFilter(this, "Subscription", new SubscriptionFilterProps {
LogGroup = logGroup,
Destination = new LambdaDestination(fn),
FilterPattern = FilterPattern.AllTerms("ERROR", "MainThread"),
FilterName = "ErrorInMainThread"
});
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import destinations "github.com/aws/aws-cdk-go/awscdk"
var fn Function
var logGroup LogGroup
logs.NewSubscriptionFilter(this, jsii.String("Subscription"), &SubscriptionFilterProps{
LogGroup: LogGroup,
Destination: destinations.NewLambdaDestination(fn),
FilterPattern: logs.FilterPattern_AllTerms(jsii.String("ERROR"), jsii.String("MainThread")),
FilterName: jsii.String("ErrorInMainThread"),
})
Initializer
new FilterPattern()
FilterPattern()
new FilterPattern()
new FilterPattern()
NewFilterPattern()
Methods
all(...patterns: JsonPattern[]): JsonPattern@staticmethod def all(patterns: JsonPattern) -> JsonPatternpublic static JsonPattern all(JsonPattern patterns)public static JsonPattern All(JsonPattern patterns)func All(Patterns JsonPattern) JsonPatternstatic#allEvents(): IFilterPattern@staticmethod def all_events() -> IFilterPatternpublic static IFilterPattern allEvents()public static IFilterPattern AllEvents()func AllEvents() IFilterPatternstatic#allTerms(...terms: string[]): IFilterPattern@staticmethod def all_terms(terms: str) -> IFilterPatternpublic static IFilterPattern allTerms(String terms)public static IFilterPattern AllTerms(string terms)func AllTerms(Terms *string) IFilterPatternstatic#1 parameter
Parameters
termstermstermstermsTerms— The words to search for.
any(...patterns: JsonPattern[]): JsonPattern@staticmethod def any(patterns: JsonPattern) -> JsonPatternpublic static JsonPattern any(JsonPattern patterns)public static JsonPattern Any(JsonPattern patterns)func Any(Patterns JsonPattern) JsonPatternstatic#anyTerm(...terms: string[]): IFilterPattern@staticmethod def any_term(terms: str) -> IFilterPatternpublic static IFilterPattern anyTerm(String terms)public static IFilterPattern AnyTerm(string terms)func AnyTerm(Terms *string) IFilterPatternstatic#1 parameter
Parameters
termstermstermstermsTerms— The words to search for.
anyTermGroup(...termGroups: string[][]): IFilterPattern@staticmethod def any_term_group(term_groups: typing.List[str]) -> IFilterPatternpublic static IFilterPattern anyTermGroup(List<String> termGroups)public static IFilterPattern AnyTermGroup(string[] termGroups)func AnyTermGroup(TermGroups *[]*string) IFilterPatternstatic#A term group matches an event if all the terms in it appear in the event string.
1 parameter
Parameters
termGroupsterm_groupstermGroupstermGroupsTermGroups— A list of term groups to search for.
booleanValue(jsonField: string, value: boolean): JsonPattern@staticmethod def boolean_value(json_field: str, value: bool) -> JsonPatternpublic static JsonPattern booleanValue(String jsonField, Boolean value)public static JsonPattern BooleanValue(string jsonField, bool value)func BooleanValue(JsonField *string, Value *bool) JsonPatternstatic#2 parameters
Parameters
jsonFieldjson_fieldjsonFieldjsonFieldJsonField— Field inside JSON.valuevaluevaluevalueValue— The value to match.
exists(jsonField: string): JsonPattern@staticmethod def exists(json_field: str) -> JsonPatternpublic static JsonPattern exists(String jsonField)public static JsonPattern Exists(string jsonField)func Exists(JsonField *string) JsonPatternstatic#This is a readable convenience wrapper over 'field = *'
1 parameter
Parameters
jsonFieldjson_fieldjsonFieldjsonFieldJsonField— Field inside JSON.
isNull(jsonField: string): JsonPattern@staticmethod def is_null(json_field: str) -> JsonPatternpublic static JsonPattern isNull(String jsonField)public static JsonPattern IsNull(string jsonField)func IsNull(JsonField *string) JsonPatternstatic#1 parameter
Parameters
jsonFieldjson_fieldjsonFieldjsonFieldJsonField— Field inside JSON.
literal(logPatternString: string): IFilterPattern@staticmethod def literal(log_pattern_string: str) -> IFilterPatternpublic static IFilterPattern literal(String logPatternString)public static IFilterPattern Literal(string logPatternString)func Literal(LogPatternString *string) IFilterPatternstatic#See https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.html for information on writing log patterns.
1 parameter
Parameters
logPatternStringlog_pattern_stringlogPatternStringlogPatternStringLogPatternString— The pattern string to use.
notExists(jsonField: string): JsonPattern@staticmethod def not_exists(json_field: str) -> JsonPatternpublic static JsonPattern notExists(String jsonField)public static JsonPattern NotExists(string jsonField)func NotExists(JsonField *string) JsonPatternstatic#1 parameter
Parameters
jsonFieldjson_fieldjsonFieldjsonFieldJsonField— Field inside JSON.
numberValue(jsonField: string, comparison: string, value: number): JsonPattern@staticmethod def number_value(json_field: str, comparison: str, value: int | float) -> JsonPatternpublic static JsonPattern numberValue(String jsonField, String comparison, Number value)public static JsonPattern NumberValue(string jsonField, string comparison, double value)func NumberValue(JsonField *string, Comparison *string, Value *float64) JsonPatternstatic#notes · 3 parameters
This pattern only matches if the event is a JSON event, and the indicated field inside compares with the value in the indicated way.
Use '$' to indicate the root of the JSON structure. The comparison operator can only compare equality or inequality. The '*' wildcard may appear in the value may at the start or at the end.
For more information, see:
Parameters
jsonFieldjson_fieldjsonFieldjsonFieldJsonField— Field inside JSON.comparisoncomparisoncomparisoncomparisonComparison— Comparison to carry out.valuevaluevaluevalueValue— The numerical value to compare to.
regexValue(jsonField: string, comparison: string, value: string): JsonPattern@staticmethod def regex_value(json_field: str, comparison: str, value: str) -> JsonPatternpublic static JsonPattern regexValue(String jsonField, String comparison, String value)public static JsonPattern RegexValue(string jsonField, string comparison, string value)func RegexValue(JsonField *string, Comparison *string, Value *string) JsonPatternstatic#notes · 3 parameters
This pattern only matches if the event is a JSON event, and the indicated field inside compares with the regex value.
Use '$' to indicate the root of the JSON structure. The comparison operator can only compare equality or inequality.
For more information, see:
Parameters
jsonFieldjson_fieldjsonFieldjsonFieldJsonField— Field inside JSON.comparisoncomparisoncomparisoncomparisonComparison— Comparison to carry out.valuevaluevaluevalueValue— The regex value to compare to.
spaceDelimited(...columns: string[]): SpaceDelimitedTextPattern@staticmethod def space_delimited(columns: str) -> SpaceDelimitedTextPatternpublic static SpaceDelimitedTextPattern spaceDelimited(String columns)public static SpaceDelimitedTextPattern SpaceDelimited(string columns)func SpaceDelimited(Columns *string) SpaceDelimitedTextPatternstatic#notes · 1 parameter
The log event is divided into space-delimited columns (optionally enclosed by "" or [] to capture spaces into column values), and names are given to each column.
'...' may be specified once to match any number of columns.
Afterwards, conditions may be added to individual columns.
Parameters
columnscolumnscolumnscolumnsColumns— The columns in the space-delimited log stream.
stringValue(jsonField: string, comparison: string, value: string): JsonPattern@staticmethod def string_value(json_field: str, comparison: str, value: str) -> JsonPatternpublic static JsonPattern stringValue(String jsonField, String comparison, String value)public static JsonPattern StringValue(string jsonField, string comparison, string value)func StringValue(JsonField *string, Comparison *string, Value *string) JsonPatternstatic#notes · 3 parameters
This pattern only matches if the event is a JSON event, and the indicated field inside compares with the string value.
Use '$' to indicate the root of the JSON structure. The comparison operator can only compare equality or inequality. The '*' wildcard may appear in the value may at the start or at the end.
For more information, see:
Parameters
jsonFieldjson_fieldjsonFieldjsonFieldJsonField— Field inside JSON.comparisoncomparisoncomparisoncomparisonComparison— Comparison to carry out.valuevaluevaluevalueValue— The string value to compare to.