@@ -4,14 +4,17 @@ import { GuLambdaFunction } from '@guardian/cdk/lib/constructs/lambda';
44import type { App } from 'aws-cdk-lib' ;
55import { Duration , Tags } from 'aws-cdk-lib' ;
66import { AttributeType , BillingMode , Table } from 'aws-cdk-lib/aws-dynamodb' ;
7+ import { EventBus , Rule } from 'aws-cdk-lib/aws-events' ;
8+ import { SqsQueue } from 'aws-cdk-lib/aws-events-targets' ;
79import { Effect , PolicyStatement } from 'aws-cdk-lib/aws-iam' ;
810import { Runtime } from 'aws-cdk-lib/aws-lambda' ;
11+ import { Queue } from 'aws-cdk-lib/aws-sqs' ;
912
1013export class LiveActivities extends GuStack {
1114 constructor ( scope : App , id : string , props : GuStackProps ) {
1215 super ( scope , id , props ) ;
1316
14- const { stack, stage } = this ;
17+ const { stack, stage, region , account } = this ;
1518 const app = 'liveactivities' ;
1619
1720 const dynamoTableName = `${ stack } -liveactivities-${ stage } ` ;
@@ -56,7 +59,7 @@ export class LiveActivities extends GuStack {
5659 actions : [ 'ssm:GetParametersByPath' ] ,
5760 effect : Effect . ALLOW ,
5861 resources : [
59- `arn:aws:ssm:${ this . region } :${ this . account } :parameter/notifications/${ this . stage } /liveactivities/ios` ,
62+ `arn:aws:ssm:${ region } :${ account } :parameter/notifications/${ stage } /liveactivities/ios` ,
6063 ] ,
6164 } ) ,
6265 ) ;
@@ -94,9 +97,37 @@ export class LiveActivities extends GuStack {
9497 actions : [ 'ssm:GetParametersByPath' ] ,
9598 effect : Effect . ALLOW ,
9699 resources : [
97- `arn:aws:ssm:${ this . region } :${ this . account } :parameter/notifications/${ this . stage } /liveactivities/ios` ,
100+ `arn:aws:ssm:${ region } :${ account } :parameter/notifications/${ stage } /liveactivities/ios` ,
98101 ] ,
99102 } ) ,
100103 ) ;
104+
105+ //////////// EVENTBUS INFRASTRUCTURE //////////////
106+
107+ const eventBus = new EventBus ( this , 'Events' , {
108+ eventBusName : `${ app } -eventbus-${ stage } ` ,
109+ description : `${ stage } event routing for live activities` ,
110+ } ) ;
111+
112+ // Development SQS to capture and inspect events from PA polling during development
113+ const liveGameTestingQueue = new Queue (
114+ this ,
115+ `${ app } -football-live-games-${ stage } ` ,
116+ {
117+ queueName : `${ app } -football-live-games-${ stage } ` ,
118+ retentionPeriod : Duration . days ( 7 ) ,
119+ } ,
120+ ) ;
121+
122+ new Rule ( this , 'liveGameEventsTargeting' , {
123+ eventBus : eventBus ,
124+ description : `Deliver live match events in ${ stage } to liveGameTestingQueue` ,
125+ eventPattern : {
126+ source : [ 'football-lambda' ] ,
127+ // detailType: ['football-match-events-with-articleId'],
128+ } ,
129+ enabled : false , // only enable if we want to inspect events in the development queue
130+ targets : [ new SqsQueue ( liveGameTestingQueue ) ] ,
131+ } ) ;
101132 }
102133}
0 commit comments