Skip to content
v2.278.0

FilterRule Class ​

Filter rules for Lambda event filtering.

Example ​

ts
import * as eventsources from 'aws-cdk-lib/aws-lambda-event-sources';
import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';

declare const fn: lambda.Function;
declare const table: dynamodb.Table;

fn.addEventSource(new eventsources.DynamoEventSource(table, {
  startingPosition: lambda.StartingPosition.LATEST,
  filters: [lambda.FilterCriteria.filter({
    eventName: lambda.FilterRule.or('INSERT', 'MODIFY'),
    dynamodb: {
      NewImage: {
        status: { S: lambda.FilterRule.beginsWith('approved') },
      },
    },
  })],
}));
python
import aws_cdk.aws_lambda_event_sources as eventsources
import aws_cdk.aws_dynamodb as dynamodb

# fn: lambda.Function
# table: dynamodb.Table


fn.add_event_source(eventsources.DynamoEventSource(table,
    starting_position=lambda_.StartingPosition.LATEST,
    filters=[lambda_.FilterCriteria.filter({
        "event_name": lambda_.FilterRule.or("INSERT", "MODIFY"),
        "dynamodb": {
            "NewImage": {
                "status": {"S": lambda_.FilterRule.begins_with("approved")}
            }
        }
    })]
))
java
import software.amazon.awscdk.services.lambda.eventsources.*;
import software.amazon.awscdk.services.dynamodb.*;

Function fn;
Table table;


fn.addEventSource(DynamoEventSource.Builder.create(table)
        .startingPosition(StartingPosition.LATEST)
        .filters(List.of(FilterCriteria.filter(Map.of(
                "eventName", FilterRule.or("INSERT", "MODIFY"),
                "dynamodb", Map.of(
                        "NewImage", Map.of(
                                "status", Map.of("S", FilterRule.beginsWith("approved"))))))))
        .build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.Lambda.EventSources;
using Amazon.CDK.AWS.DynamoDB;

Function fn;
Table table;


fn.AddEventSource(new DynamoEventSource(table, new DynamoEventSourceProps {
    StartingPosition = StartingPosition.LATEST,
    Filters = new [] { FilterCriteria.Filter(new Dictionary<string, object> {
        { "eventName", FilterRule.Or("INSERT", "MODIFY") },
        { "dynamodb", new Dictionary<string, IDictionary<string, IDictionary<string, IDictionary<string, string>[]>>> {
            { "NewImage", new Struct {
                Status = new Struct { S = FilterRule.BeginsWith("approved") }
            } }
        } }
    }) }
}));
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import eventsources "github.com/aws/aws-cdk-go/awscdk"
import dynamodb "github.com/aws/aws-cdk-go/awscdk"

var fn Function
var table Table


fn.AddEventSource(eventsources.NewDynamoEventSource(table, &DynamoEventSourceProps{
	StartingPosition: lambda.StartingPosition_LATEST,
	Filters: []map[string]interface{}{
		lambda.FilterCriteria_Filter(map[string]interface{}{
			"eventName": lambda.FilterRule_or(jsii.String("INSERT"), jsii.String("MODIFY")),
			"dynamodb": map[string]map[string]map[string][]map[string]*string{
				"NewImage": map[string]map[string][]map[string]*string{
					"status": map[string][]map[string]*string{
						"S": lambda.FilterRule_beginsWith(jsii.String("approved")),
					},
				},
			},
		}),
	},
}))

Initializer ​

ts
new FilterRule()
python
FilterRule()
java
new FilterRule()
csharp
new FilterRule()
go
NewFilterRule()

Methods ​

beginsWith(elem: string): { [key: string]: string }[]@staticmethod def begins_with(elem: str) -> typing.List[typing.Mapping[str, str]]public static List<Map<String, String>> beginsWith(String elem)public static IDictionary<string, string>[] BeginsWith(string elem)func BeginsWith(Elem *string) *[]*map[string]*string static #
Begins with comparison operator.
between(first: number, second: number): { [key: string]: any[] }[]@staticmethod def between(first: int | float, second: int | float) -> typing.List[typing.Mapping[str, typing.List[Any]]]public static List<Map<String, List<Object>>> between(Number first, Number second)public static IDictionary<string, object[]>[] Between(double first, double second)func Between(First *float64, Second *float64) *[]*map[string]*[]interface{} static #
Numeric range comparison operator.
empty(): string[]@staticmethod def empty() -> typing.List[str]public static List<String> empty()public static string[] Empty()func Empty() *[]*string static #
Empty comparison operator.
exists(): { [key: string]: boolean }[]@staticmethod def exists() -> typing.List[typing.Mapping[str, bool]]public static List<Map<String, Boolean>> exists()public static IDictionary<string, bool>[] Exists()func Exists() *[]*map[string]*bool static #
Exists comparison operator.
isEqual(item: string | number | boolean): any@staticmethod def is_equal(item: typing.Union[str, int | float, bool]) -> Anypublic static Object isEqual(String item)public static object IsEqual(string item)func IsEqual(Item interface{}) interface{} static #
Equals comparison operator.
notEquals(elem: string): { [key: string]: string[] }[]@staticmethod def not_equals(elem: str) -> typing.List[typing.Mapping[str, typing.List[str]]]public static List<Map<String, List<String>>> notEquals(String elem)public static IDictionary<string, string[]>[] NotEquals(string elem)func NotEquals(Elem *string) *[]*map[string]*[]*string static #
Not equals comparison operator.
notExists(): { [key: string]: boolean }[]@staticmethod def not_exists() -> typing.List[typing.Mapping[str, bool]]public static List<Map<String, Boolean>> notExists()public static IDictionary<string, bool>[] NotExists()func NotExists() *[]*map[string]*bool static #
Not exists comparison operator.
null(): any@staticmethod def null() -> Anypublic static Object null()public static object Null()func Null() interface{} static #
Null comparison operator.
or(...elem: string[]): string[]@staticmethod def or(elem: str) -> typing.List[str]public static List<String> or(String elem)public static string[] Or(string elem)func Or(Elem *string) *[]*string static #
Or comparison operator.