Skip to content
v2.273.0

SubscriptionFilter Class ​

A subscription filter for an attribute.

Example ​

ts
import * as lambda from 'aws-cdk-lib/aws-lambda';

const myTopic = new sns.Topic(this, 'MyTopic');
declare const fn: lambda.Function;

// Lambda should receive only message matching the following conditions on attributes:
// color: 'red' or 'orange' or begins with 'bl'
// size: anything but 'small' or 'medium'
// price: between 100 and 200 or greater than 300
// store: attribute must be present
myTopic.addSubscription(new subscriptions.LambdaSubscription(fn, {
  filterPolicy: {
    color: sns.SubscriptionFilter.stringFilter({
      allowlist: ['red', 'orange'],
      matchPrefixes: ['bl'],
      matchSuffixes: ['ue'],
    }),
    size: sns.SubscriptionFilter.stringFilter({
      denylist: ['small', 'medium'],
    }),
    price: sns.SubscriptionFilter.numericFilter({
      between: { start: 100, stop: 200 },
      greaterThan: 300,
    }),
    store: sns.SubscriptionFilter.existsFilter(),
  },
}));
python
import aws_cdk.aws_lambda as lambda_
# fn: lambda.Function


my_topic = sns.Topic(self, "MyTopic")

# Lambda should receive only message matching the following conditions on attributes:
# color: 'red' or 'orange' or begins with 'bl'
# size: anything but 'small' or 'medium'
# price: between 100 and 200 or greater than 300
# store: attribute must be present
my_topic.add_subscription(subscriptions.LambdaSubscription(fn,
    filter_policy={
        "color": sns.SubscriptionFilter.string_filter(
            allowlist=["red", "orange"],
            match_prefixes=["bl"],
            match_suffixes=["ue"]
        ),
        "size": sns.SubscriptionFilter.string_filter(
            denylist=["small", "medium"]
        ),
        "price": sns.SubscriptionFilter.numeric_filter(
            between=sns.BetweenCondition(start=100, stop=200),
            greater_than=300
        ),
        "store": sns.SubscriptionFilter.exists_filter()
    }
))
java
import software.amazon.awscdk.services.lambda.*;
Function fn;


Topic myTopic = new Topic(this, "MyTopic");

// Lambda should receive only message matching the following conditions on attributes:
// color: 'red' or 'orange' or begins with 'bl'
// size: anything but 'small' or 'medium'
// price: between 100 and 200 or greater than 300
// store: attribute must be present
myTopic.addSubscription(LambdaSubscription.Builder.create(fn)
        .filterPolicy(Map.of(
                "color", SubscriptionFilter.stringFilter(StringConditions.builder()
                        .allowlist(List.of("red", "orange"))
                        .matchPrefixes(List.of("bl"))
                        .matchSuffixes(List.of("ue"))
                        .build()),
                "size", SubscriptionFilter.stringFilter(StringConditions.builder()
                        .denylist(List.of("small", "medium"))
                        .build()),
                "price", SubscriptionFilter.numericFilter(NumericConditions.builder()
                        .between(BetweenCondition.builder().start(100).stop(200).build())
                        .greaterThan(300)
                        .build()),
                "store", SubscriptionFilter.existsFilter()))
        .build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.Lambda;
Function fn;


var myTopic = new Topic(this, "MyTopic");

// Lambda should receive only message matching the following conditions on attributes:
// color: 'red' or 'orange' or begins with 'bl'
// size: anything but 'small' or 'medium'
// price: between 100 and 200 or greater than 300
// store: attribute must be present
myTopic.AddSubscription(new LambdaSubscription(fn, new LambdaSubscriptionProps {
    FilterPolicy = new Dictionary<string, SubscriptionFilter> {
        { "color", SubscriptionFilter.StringFilter(new StringConditions {
            Allowlist = new [] { "red", "orange" },
            MatchPrefixes = new [] { "bl" },
            MatchSuffixes = new [] { "ue" }
        }) },
        { "size", SubscriptionFilter.StringFilter(new StringConditions {
            Denylist = new [] { "small", "medium" }
        }) },
        { "price", SubscriptionFilter.NumericFilter(new NumericConditions {
            Between = new BetweenCondition { Start = 100, Stop = 200 },
            GreaterThan = 300
        }) },
        { "store", SubscriptionFilter.ExistsFilter() }
    }
}));
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import lambda "github.com/aws/aws-cdk-go/awscdk"
var fn Function


myTopic := sns.NewTopic(this, jsii.String("MyTopic"))

// Lambda should receive only message matching the following conditions on attributes:
// color: 'red' or 'orange' or begins with 'bl'
// size: anything but 'small' or 'medium'
// price: between 100 and 200 or greater than 300
// store: attribute must be present
myTopic.AddSubscription(subscriptions.NewLambdaSubscription(fn, &LambdaSubscriptionProps{
	FilterPolicy: map[string]SubscriptionFilter{
		"color": sns.SubscriptionFilter_stringFilter(&StringConditions{
			"allowlist": []*string{
				jsii.String("red"),
				jsii.String("orange"),
			},
			"matchPrefixes": []*string{
				jsii.String("bl"),
			},
			"matchSuffixes": []*string{
				jsii.String("ue"),
			},
		}),
		"size": sns.SubscriptionFilter_stringFilter(&StringConditions{
			"denylist": []*string{
				jsii.String("small"),
				jsii.String("medium"),
			},
		}),
		"price": sns.SubscriptionFilter_numericFilter(&NumericConditions{
			"between": &BetweenCondition{
				"start": jsii.Number(100),
				"stop": jsii.Number(200),
			},
			"greaterThan": jsii.Number(300),
		}),
		"store": sns.SubscriptionFilter_existsFilter(),
	},
}))

Initializer ​

ts
new SubscriptionFilter(conditions?: any[])
python
SubscriptionFilter(conditions: typing.Optional[typing.List[Any]] = None)
java
new SubscriptionFilter(List<Object> conditions)
csharp
new SubscriptionFilter(object[]? conditions = null)
go
NewSubscriptionFilter(Conditions *[]interface{})

Properties ​

conditionsany[]conditionstyping.List[Any]conditionsList<Object>Conditionsobject[]Conditions*[]interface{}required#
conditions that specify the message attributes that should be included, excluded, matched, etc.

Methods ​

existsFilter(): SubscriptionFilter // chainable@staticmethod def exists_filter() -> SubscriptionFilterpublic static SubscriptionFilter existsFilter()public static SubscriptionFilter ExistsFilter()func ExistsFilter() SubscriptionFilterstatic#
Returns a subscription filter for attribute key matching.
notExistsFilter(): SubscriptionFilter // chainable@staticmethod def not_exists_filter() -> SubscriptionFilterpublic static SubscriptionFilter notExistsFilter()public static SubscriptionFilter NotExistsFilter()func NotExistsFilter() SubscriptionFilterstatic#
Returns a subscription filter for absence of attribute key.
numericFilter(numericConditions: NumericConditions): SubscriptionFilter // chainable@staticmethod def numeric_filter(numeric_conditions: NumericConditions) -> SubscriptionFilterpublic static SubscriptionFilter numericFilter(NumericConditions numericConditions)public static SubscriptionFilter NumericFilter(NumericConditions numericConditions)func NumericFilter(NumericConditions NumericConditions) SubscriptionFilterstatic#
Returns a subscription filter for a numeric attribute.
stringFilter(stringConditions: StringConditions): SubscriptionFilter // chainable@staticmethod def string_filter(string_conditions: StringConditions) -> SubscriptionFilterpublic static SubscriptionFilter stringFilter(StringConditions stringConditions)public static SubscriptionFilter StringFilter(StringConditions stringConditions)func StringFilter(StringConditions StringConditions) SubscriptionFilterstatic#
Returns a subscription filter for a string attribute.