StringConditions Struct
Conditions that can be applied to string attributes.
| Source | aws-sns/lib/subscription-filter.ts |
|---|---|
| Type last changed |
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(),
},
}))
Properties
allowlistoptionalstring[]allowlistoptionaltyping.List[str]allowlistoptionalList<String>Allowlistoptionalstring[]Allowlistoptional*[]*string = None #Match one or more values.
denylistoptionalstring[]denylistoptionaltyping.List[str]denylistoptionalList<String>Denylistoptionalstring[]Denylistoptional*[]*string = None #Match any value that doesn't include any of the specified values.
matchPrefixesoptionalstring[]match_prefixesoptionaltyping.List[str]matchPrefixesoptionalList<String>MatchPrefixesoptionalstring[]MatchPrefixesoptional*[]*string = None #Matches values that begins with the specified prefixes.
matchSuffixesoptionalstring[]match_suffixesoptionaltyping.List[str]matchSuffixesoptionalList<String>MatchSuffixesoptionalstring[]MatchSuffixesoptional*[]*string = None #Matches values that end with the specified suffixes.