topic.py
 1  """SNS Topic for WhatsApp End User Messaging events."""
 2  
 3  from constructs import Construct
 4  from aws_cdk import (
 5      aws_sns as sns,
 6      aws_iam as iam,
 7  )
 8  
 9  
10  class WhatsAppTopic(Construct):
11      """SNS topic that receives WhatsApp webhook events from AWS Social Messaging."""
12  
13      def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
14          super().__init__(scope, construct_id, **kwargs)
15  
16          self.topic = sns.Topic(
17              self,
18              "WhatsAppEventsTopic",
19              display_name="WhatsApp Events",
20          )
21  
22          self.topic.add_to_resource_policy(
23              iam.PolicyStatement(
24                  actions=["sns:Publish"],
25                  principals=[iam.ServicePrincipal("social-messaging.amazonaws.com")],
26                  resources=[self.topic.topic_arn],
27              )
28          )