From 850b1505e9c12fe0452910e0a7e83bc0a9810548 Mon Sep 17 00:00:00 2001 From: epolon Date: Wed, 20 Nov 2024 12:59:02 +0200 Subject: [PATCH] mid work --- packages/aws-cdk/lib/api/aws-auth/sdk.ts | 10 ++++---- .../util/cloudformation/stack-event-poller.ts | 23 +++++++++++-------- .../cloudformation/stack-event-poller.test.ts | 6 ++--- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/packages/aws-cdk/lib/api/aws-auth/sdk.ts b/packages/aws-cdk/lib/api/aws-auth/sdk.ts index 9b38cf5ef8452..5dc345226824f 100644 --- a/packages/aws-cdk/lib/api/aws-auth/sdk.ts +++ b/packages/aws-cdk/lib/api/aws-auth/sdk.ts @@ -51,6 +51,7 @@ import { DescribeResourceScanCommand, type DescribeResourceScanCommandInput, type DescribeResourceScanCommandOutput, + DescribeStackEventsCommand, type DescribeStackEventsCommandInput, DescribeStackEventsCommandOutput, DescribeStackResourcesCommand, @@ -87,7 +88,6 @@ import { ListStacksCommand, ListStacksCommandInput, ListStacksCommandOutput, - paginateDescribeStackEvents, paginateListStackResources, RollbackStackCommand, RollbackStackCommandInput, @@ -311,7 +311,7 @@ import { GetCallerIdentityCommand, STSClient } from '@aws-sdk/client-sts'; import { Upload } from '@aws-sdk/lib-storage'; import { getEndpointFromInstructions } from '@smithy/middleware-endpoint'; import type { NodeHttpHandlerOptions } from '@smithy/node-http-handler'; -import { AwsCredentialIdentity, Logger, Paginator } from '@smithy/types'; +import { AwsCredentialIdentity, Logger } from '@smithy/types'; import { ConfiguredRetryStrategy } from '@smithy/util-retry'; import { WaiterResult } from '@smithy/util-waiter'; import { AccountAccessKeyCache } from './account-cache'; @@ -404,7 +404,7 @@ export interface ICloudFormationClient { input: UpdateTerminationProtectionCommandInput, ): Promise; // Pagination functions - describeStackEventsPaginated(input: DescribeStackEventsCommandInput): Paginator; + describeStackEvents(input: DescribeStackEventsCommandInput): Promise; listStackResources(input: ListStackResourcesCommandInput): Promise; } @@ -664,8 +664,8 @@ export class SDK { input: UpdateTerminationProtectionCommandInput, ): Promise => client.send(new UpdateTerminationProtectionCommand(input)), - describeStackEventsPaginated: (input: DescribeStackEventsCommandInput): Paginator => { - return paginateDescribeStackEvents({ client }, input); + describeStackEvents: (input: DescribeStackEventsCommandInput): Promise => { + return client.send(new DescribeStackEventsCommand(input)); }, listStackResources: async (input: ListStackResourcesCommandInput): Promise => { const stackResources = Array(); diff --git a/packages/aws-cdk/lib/api/util/cloudformation/stack-event-poller.ts b/packages/aws-cdk/lib/api/util/cloudformation/stack-event-poller.ts index 8ff1a728d4cdf..efc66da8ef3b0 100644 --- a/packages/aws-cdk/lib/api/util/cloudformation/stack-event-poller.ts +++ b/packages/aws-cdk/lib/api/util/cloudformation/stack-event-poller.ts @@ -88,10 +88,11 @@ export class StackEventPoller { private async doPoll(): Promise { const events: ResourceEvent[] = []; try { - const paginator = this.cfn.describeStackEventsPaginated({ - StackName: this.props.stackName, - }); - for await (const page of paginator) { + 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) { @@ -107,7 +108,6 @@ export class StackEventPoller { // 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; - /* istanbul ignore next */ if (isParentStackEvent && this.props.stackStatuses?.includes(event.ResourceStatus ?? '')) { return events; } @@ -122,22 +122,25 @@ export class StackEventPoller { if ( !isParentStackEvent && - event.ResourceType === 'AWS::CloudFormation::Stack' && - isStackBeginOperationState(event.ResourceStatus) + event.ResourceType === 'AWS::CloudFormation::Stack' && + isStackBeginOperationState(event.ResourceStatus) ) { - /* istanbul ignore next */ // 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 ?? '']); } - /* istanbul ignore next */ if (isParentStackEvent && isStackTerminalState(event.ResourceStatus)) { this.complete = true; } } + + nextToken = page?.NextToken; + if (nextToken === undefined) { + finished = true; + } + } } catch (e: any) { - /* istanbul ignore next */ if (!(e.name === 'ValidationError' && e.message === `Stack [${this.props.stackName}] does not exist`)) { throw e; } diff --git a/packages/aws-cdk/test/api/util/cloudformation/stack-event-poller.test.ts b/packages/aws-cdk/test/api/util/cloudformation/stack-event-poller.test.ts index 1a93e3627c266..6ff65e4eba58f 100644 --- a/packages/aws-cdk/test/api/util/cloudformation/stack-event-poller.test.ts +++ b/packages/aws-cdk/test/api/util/cloudformation/stack-event-poller.test.ts @@ -29,8 +29,8 @@ describe('poll', () => { const sdk = new MockSdk(); mockCloudFormationClient.on(DescribeStackEventsCommand).callsFake((input: DescribeStackEventsCommandInput) => { const result = { - StackEvents: input.NextToken ? [postDeployEvent2] : [postDeployEvent1], - NextToken: input.NextToken ? undefined : 'token', // simulate a two page event stream. + StackEvents: input.NextToken === 'token' ? [postDeployEvent2] : [postDeployEvent1], + NextToken: input.NextToken === 'token' ? undefined : 'token', // simulate a two page event stream. }; return result; @@ -66,7 +66,7 @@ describe('poll', () => { return { StackEvents: [preDeployTimeEvent], - NextToken: input.NextToken ? undefined : 'token', // simulate a two page event stream. + NextToken: input.NextToken === 'token' ? undefined : 'token', // simulate a two page event stream. }; });