MCPcopy Create free account
hub / github.com/aws-samples/aws-cdk-examples / ConsumerStack

Class ConsumerStack

python/eventbridge-mesh/single-consumer/app.py:45–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43
44
45class ConsumerStack(Stack):
46 def __init__(self, scope: Construct, id: str, *,
47 app_name: str,
48 producer_account_id: str,
49 **kwargs) -> None:
50 super().__init__(scope, id, **kwargs)
51
52 # Create or reference the consumer event bus
53 consumer_event_bus = events.EventBus(
54 self, f"{app_name}-consumer-event-bus"
55 )
56
57 # Add policy to allow producer account to put events
58 consumer_event_bus.add_to_resource_policy(iam.PolicyStatement(
59 sid="allowProducerAccount",
60 effect=iam.Effect.ALLOW,
61 principals=[iam.AccountPrincipal(producer_account_id)],
62 actions=["events:PutEvents"],
63 resources=[consumer_event_bus.event_bus_arn]
64 ))
65
66 # Create consumer rules
67 consumer_rule = events.Rule(
68 self, f"{app_name}-consumer-rule",
69 event_bus=consumer_event_bus,
70 event_pattern=events.EventPattern(
71 source=['com.myapp.events'],
72 detail_type=['specific-event-type']
73 )
74 )
75
76 # Add target (e.g., CloudWatch)
77 log_group = logs.LogGroup(self, f"{app_name}-consumer-logs")
78 consumer_rule.add_target(targets.CloudWatchLogGroup(log_group))
79
80
81app = App()

Callers 1

app.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected