LambdaSubscription

class aws_cdk.aws_sns_subscriptions.LambdaSubscription(fn, *, dead_letter_queue=None, filter_policy=None, filter_policy_with_message_body=None)

Bases: object

Use a Lambda function as a subscription target.

ExampleMetadata:

infused

Example:

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 message body:
# color: 'red' or 'orange'
my_topic.add_subscription(subscriptions.LambdaSubscription(fn,
    filter_policy_with_message_body={
        "background": sns.FilterOrPolicy.policy({
            "color": sns.FilterOrPolicy.filter(sns.SubscriptionFilter.string_filter(
                allowlist=["red", "orange"]
            ))
        })
    }
))
Parameters:
  • fn (IFunction) –

  • dead_letter_queue (Optional[IQueue]) – Queue to be used as dead letter queue. If not passed no dead letter queue is enabled. Default: - No dead letter queue enabled.

  • filter_policy (Optional[Mapping[str, SubscriptionFilter]]) – The filter policy. Default: - all messages are delivered

  • filter_policy_with_message_body (Optional[Mapping[str, FilterOrPolicy]]) – The filter policy that is applied on the message body. To apply a filter policy to the message attributes, use filterPolicy. A maximum of one of filterPolicyWithMessageBody and filterPolicy may be used. Default: - all messages are delivered

Methods

bind(topic)

Returns a configuration for a Lambda function to subscribe to an SNS topic.

Parameters:

topic (ITopic) –

Return type:

TopicSubscriptionConfig