@@ -10,7 +10,12 @@ import {
1010 TreatMissingData ,
1111 Unit ,
1212} from 'aws-cdk-lib/aws-cloudwatch' ;
13- import { AttributeType , BillingMode , Table } from 'aws-cdk-lib/aws-dynamodb' ;
13+ import {
14+ AttributeType ,
15+ BillingMode ,
16+ ProjectionType ,
17+ Table ,
18+ } from 'aws-cdk-lib/aws-dynamodb' ;
1419import { Schedule } from 'aws-cdk-lib/aws-events' ;
1520import { Effect , PolicyStatement } from 'aws-cdk-lib/aws-iam' ;
1621import { LoggingFormat , Runtime } from 'aws-cdk-lib/aws-lambda' ;
@@ -71,8 +76,8 @@ export class FootballNotificationsLambda extends GuStack {
7176 } ) ,
7277 ) ;
7378
79+ // DynamoDB Push Notifications Table
7480 const dynamoTableName = `${ stack } -football-notifications-${ stage } ` ;
75-
7681 const dynamoTable = new Table ( this , 'DynamoTable' , {
7782 tableName : dynamoTableName ,
7883 partitionKey : { name : 'notificationId' , type : AttributeType . STRING } ,
@@ -85,13 +90,11 @@ export class FootballNotificationsLambda extends GuStack {
8590 logicalId : 'DynamoTable' ,
8691 reason : 'Retaining a stateful resource previously defined in YAML' ,
8792 } ) ;
88-
8993 Tags . of ( dynamoTable ) . add ( 'devx-backup-enabled' , 'true' ) ;
9094
91- // Live Activities DynamoDB Table
95+ // DynamoDB Live Activities Payloads Table
9296 const liveActivitiesAppName = 'liveactivities' ;
9397 const liveActivitiesDynamoTableName = `${ stack } -${ liveActivitiesAppName } -payload-${ stage } ` ;
94-
9598 const liveActivitiesDynamoTable = new Table (
9699 this ,
97100 'LiveActivitiesDynamoTable' ,
@@ -104,6 +107,14 @@ export class FootballNotificationsLambda extends GuStack {
104107 ) ;
105108 Tags . of ( liveActivitiesDynamoTable ) . add ( 'devx-backup-enabled' , 'true' ) ;
106109
110+ // GSI is used to determine if an untracked state change event has occurred, ie. goal was overruled.
111+ liveActivitiesDynamoTable . addGlobalSecondaryIndex ( {
112+ indexName : 'lastPayload-index' ,
113+ partitionKey : { name : 'liveActivityID' , type : AttributeType . STRING } ,
114+ sortKey : { name : 'ttl' , type : AttributeType . NUMBER } ,
115+ projectionType : ProjectionType . ALL ,
116+ } ) ;
117+
107118 footballnotificationslambda . addToRolePolicy (
108119 new PolicyStatement ( {
109120 actions : [
0 commit comments