@@ -88,65 +88,64 @@ export class StackEventPoller {
88
88
private async doPoll ( ) : Promise < ResourceEvent [ ] > {
89
89
const events : ResourceEvent [ ] = [ ] ;
90
90
try {
91
- const eventList = await this . cfn . describeStackEvents ( {
92
- StackName : this . props . stackName ,
93
- } ) ;
94
- for ( const event of eventList ) {
95
- // Event from before we were interested in 'em
96
- if ( this . props . startTime !== undefined && event . Timestamp ! . valueOf ( ) < this . props . startTime ) {
97
- return events ;
98
- }
99
-
100
- // Already seen this one
101
- if ( this . eventIds . has ( event . EventId ! ) ) {
102
- return events ;
103
- }
104
- this . eventIds . add ( event . EventId ! ) ;
105
-
106
- // The events for the stack itself are also included next to events about resources; we can test for them in this way.
107
- const isParentStackEvent = event . PhysicalResourceId === event . StackId ;
108
-
109
- if ( isParentStackEvent && this . props . stackStatuses ?. includes ( event . ResourceStatus ?? '' ) ) {
110
- return events ;
91
+ let nextToken : string | undefined ;
92
+ let finished = false ;
93
+
94
+ while ( ! finished ) {
95
+ const page = await this . cfn . describeStackEvents ( { StackName : this . props . stackName , NextToken : nextToken } ) ;
96
+ for ( const event of page ?. StackEvents ?? [ ] ) {
97
+ // Event from before we were interested in 'em
98
+ if ( this . props . startTime !== undefined && event . Timestamp ! . valueOf ( ) < this . props . startTime ) {
99
+ return events ;
100
+ }
101
+
102
+ // Already seen this one
103
+ if ( this . eventIds . has ( event . EventId ! ) ) {
104
+ return events ;
105
+ }
106
+ this . eventIds . add ( event . EventId ! ) ;
107
+
108
+ // The events for the stack itself are also included next to events about resources; we can test for them in this way.
109
+ const isParentStackEvent = event . PhysicalResourceId === event . StackId ;
110
+
111
+ if ( isParentStackEvent && this . props . stackStatuses ?. includes ( event . ResourceStatus ?? '' ) ) {
112
+ return events ;
113
+ }
114
+
115
+ // Fresh event
116
+ const resEvent : ResourceEvent = {
117
+ event : event ,
118
+ parentStackLogicalIds : this . props . parentStackLogicalIds ?? [ ] ,
119
+ isStackEvent : isParentStackEvent ,
120
+ } ;
121
+ events . push ( resEvent ) ;
122
+
123
+ if (
124
+ ! isParentStackEvent &&
125
+ event . ResourceType === 'AWS::CloudFormation::Stack' &&
126
+ isStackBeginOperationState ( event . ResourceStatus )
127
+ ) {
128
+ // If the event is not for `this` stack and has a physical resource Id, recursively call for events in the nested stack
129
+ this . trackNestedStack ( event , [ ...( this . props . parentStackLogicalIds ?? [ ] ) , event . LogicalResourceId ?? '' ] ) ;
130
+ }
131
+
132
+ if ( isParentStackEvent && isStackTerminalState ( event . ResourceStatus ) ) {
133
+ this . complete = true ;
134
+ }
111
135
}
112
136
113
- // Fresh event
114
- const resEvent : ResourceEvent = {
115
- event : event ,
116
- parentStackLogicalIds : this . props . parentStackLogicalIds ?? [ ] ,
117
- isStackEvent : isParentStackEvent ,
118
- } ;
119
- events . push ( resEvent ) ;
120
-
121
- if (
122
- ! isParentStackEvent &&
123
- event . ResourceType === 'AWS::CloudFormation::Stack' &&
124
- isStackBeginOperationState ( event . ResourceStatus )
125
- ) {
126
- // If the event is not for `this` stack and has a physical resource Id, recursively call for events in the nested stack
127
- this . trackNestedStack ( event , [ ...( this . props . parentStackLogicalIds ?? [ ] ) , event . LogicalResourceId ?? '' ] ) ;
137
+ nextToken = page ?. NextToken ;
138
+ if ( nextToken === undefined ) {
139
+ finished = true ;
128
140
}
129
141
130
- if ( isParentStackEvent && isStackTerminalState ( event . ResourceStatus ) ) {
131
- this . complete = true ;
132
- }
133
142
}
134
143
} catch ( e : any ) {
135
144
if ( ! ( e . name === 'ValidationError' && e . message === `Stack [${ this . props . stackName } ] does not exist` ) ) {
136
145
throw e ;
137
146
}
138
147
}
139
- // // Also poll all nested stacks we're currently tracking
140
- // for (const [logicalId, poller] of Object.entries(this.nestedStackPollers)) {
141
- // events.push(...(await poller.poll()));
142
- // if (poller.complete) {
143
- // delete this.nestedStackPollers[logicalId];
144
- // }
145
- // }
146
-
147
- // // Return what we have so far
148
- // events.sort((a, b) => a.event.Timestamp!.valueOf() - b.event.Timestamp!.valueOf());
149
- // this.events.push(...events);
148
+
150
149
return events ;
151
150
}
152
151
0 commit comments