Skip to content
v2.278.0

LambdaSubscriptionProps Struct ​

Properties for a Lambda subscription.

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 ​

deadLetterQueueoptionalIQueuedead_letter_queueoptionalIQueuedeadLetterQueueoptionalIQueueDeadLetterQueueoptionalIQueueDeadLetterQueueoptionalIQueue #
Queue to be used as dead letter queue.

Default: No dead letter queue enabled.

If not passed no dead letter queue is enabled.

filterPolicyoptional{ [key: string]: SubscriptionFilter }filter_policyoptionaltyping.Mapping[str, SubscriptionFilter]filterPolicyoptionalMap<String, SubscriptionFilter>FilterPolicyoptionalIDictionary<string, SubscriptionFilter>FilterPolicyoptional*map[string]SubscriptionFilter #
The filter policy.

Default: all messages are delivered

filterPolicyWithMessageBodyoptional{ [key: string]: FilterOrPolicy }filter_policy_with_message_bodyoptionaltyping.Mapping[str, FilterOrPolicy]filterPolicyWithMessageBodyoptionalMap<String, FilterOrPolicy>FilterPolicyWithMessageBodyoptionalIDictionary<string, FilterOrPolicy>FilterPolicyWithMessageBodyoptional*map[string]FilterOrPolicy #
The filter policy that is applied on the message body.

Default: all messages are delivered

To apply a filter policy to the message attributes, use filterPolicy. A maximum of one of filterPolicyWithMessageBody and filterPolicy may be used.