in packages/@aws-cdk/toolkit-lib/lib/api/stack-events/stack-event-poller.ts [97:158]
private async doPoll(): Promise<ResourceEvent[]> {
const events: ResourceEvent[] = [];
try {
let nextToken: string | undefined;
let finished = false;
while (!finished) {
const page = await this.cfn.describeStackEvents({ StackName: this.props.stackName, NextToken: nextToken });
for (const event of page?.StackEvents ?? []) {
// Event from before we were interested in 'em
if (this.props.startTime !== undefined && event.Timestamp!.valueOf() < this.props.startTime) {
return events;
}
// Already seen this one
if (this.eventIds.has(event.EventId!)) {
return events;
}
this.eventIds.add(event.EventId!);
// The events for the stack itself are also included next to events about resources; we can test for them in this way.
const isParentStackEvent = event.PhysicalResourceId === event.StackId;
if (isParentStackEvent && this.props.stackStatuses?.includes(event.ResourceStatus ?? '')) {
return events;
}
// Fresh event
const resEvent: ResourceEvent = {
event: event,
parentStackLogicalIds: this.props.parentStackLogicalIds ?? [],
isStackEvent: isParentStackEvent,
};
events.push(resEvent);
if (
!isParentStackEvent &&
event.ResourceType === 'AWS::CloudFormation::Stack' &&
isStackBeginOperationState(event.ResourceStatus)
) {
// If the event is not for `this` stack and has a physical resource Id, recursively call for events in the nested stack
this.trackNestedStack(event, [...(this.props.parentStackLogicalIds ?? []), event.LogicalResourceId ?? '']);
}
if (isParentStackEvent && isStackTerminalState(event.ResourceStatus)) {
this.complete = true;
}
}
nextToken = page?.NextToken;
if (nextToken === undefined) {
finished = true;
}
}
} catch (e: any) {
if (!(e.name === 'ValidationError' && formatErrorMessage(e) === `Stack [${this.props.stackName}] does not exist`)) {
throw e;
}
}
return events;
}