Skip to content

feat(toolkit-lib): configurable stack event polling interval on deploy and destroy#1710

Merged
aws-cdk-automation merged 1 commit into
aws:mainfrom
svozza:feat/toolkit-lib-polling-interval
Jul 7, 2026
Merged

feat(toolkit-lib): configurable stack event polling interval on deploy and destroy#1710
aws-cdk-automation merged 1 commit into
aws:mainfrom
svozza:feat/toolkit-lib-polling-interval

Conversation

@svozza

@svozza svozza commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Fixes #1709

Motivation

StackActivityMonitor polls DescribeStackEvents every 2 seconds per active stack operation, and the interval is hardcoded. Programmatic consumers running large CI matrices (the Powertools for AWS Lambda (TypeScript) team reports ~50–100 concurrent stack operations) saturate the account-level CloudFormation read API and fail with CDK_TOOLKIT_E5500/CDK_TOOLKIT_E7900 "Throttling: Rate exceeded".

Of the placements proposed in the issue, this implements the per-action option on DeployOptions/DestroyOptions rather than a global setting on ToolkitOptions, keeping the new surface scoped to the actions that construct the monitor.

Changes

  • New optional stackEventPollingInterval (milliseconds) on DeployOptions and DestroyOptions.
  • Threaded through Toolkit.deploy()/Toolkit.destroy()Deployments.deployStack()/destroyStack() → the two new StackActivityMonitor(...) construction sites in deploy-stack.ts. The monitor already supported pollingInterval; this only wires it up.
  • Default unchanged (2000 ms) — fully backward compatible when the option is unset.
  • Not included: the rollback monitor (Deployments.rollbackStack). This PR covers the deploy and destroy paths from the issue; happy to extend to RollbackStackOptions here or in a follow-up if preferred.

Testing

  • Unit tests at all three layers: action option pass-through (deploy.test.ts, destroy.test.ts), Deployments forwarding (cloudformation-deployments.test.ts), and monitor construction (deploy-stack-polling-interval.test.ts), including asserting the default stays 2 s when the option is unset.
  • The monitor-construction tests live in a new file rather than the existing deploy-stack.test.ts: they verify the props passed to new StackActivityMonitor(...) by wrapping the constructor via a module-level jest.mock, which jest hoists file-wide. deploy-stack.test.ts doesn't install that mock, so adding it there would have changed the module graph for all ~60 existing tests in that file — a separate file keeps the mock's blast radius to just these four tests.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

…y and destroy

The StackActivityMonitor polls DescribeStackEvents every 2 seconds per
active stack operation and the interval is not configurable. Large CI
matrices driving toolkit-lib programmatically saturate the account-level
CloudFormation read API and fail with throttling errors.

Add an optional stackEventPollingInterval (milliseconds) to DeployOptions
and DestroyOptions and thread it through Deployments and
deployStack/destroyStack to the monitor. The default is unchanged (2000 ms).

Closes aws#1709
@github-actions github-actions Bot added the p2 label Jul 7, 2026
@svozza
svozza temporarily deployed to integ-approval July 7, 2026 16:03 — with GitHub Actions Inactive
@aws-cdk-automation
aws-cdk-automation requested a review from a team July 7, 2026 16:03
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.62%. Comparing base (473013f) to head (f1df7da).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1710      +/-   ##
==========================================
+ Coverage   89.61%   89.62%   +0.01%     
==========================================
  Files          77       77              
  Lines       11752    11752              
  Branches     1650     1650              
==========================================
+ Hits        10531    10533       +2     
+ Misses       1192     1190       -2     
  Partials       29       29              
Flag Coverage Δ
suite.unit 89.62% <ø> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@aws-cdk-automation
aws-cdk-automation added this pull request to the merge queue Jul 7, 2026
Merged via the queue into aws:main with commit 8580fe4 Jul 7, 2026
46 checks passed
amitaysh pushed a commit to amitaysh/aws-cdk-cli that referenced this pull request Jul 12, 2026
…on deploy, destroy and prepareStack (aws#1724)

Fixes aws#1723

### Motivation

Follow-on to aws#1709/aws#1710, which made the `StackActivityMonitor`
event-polling interval (`DescribeStackEvents`) configurable via
`stackEventPollingInterval`. There's a second hardcoded polling loop
that wasn't touched: the stabilization waiter. `stabilizeStack()` in
`lib/api/deployments/cfn-api.ts` — via the exported
`waitForStackDeploy()`/`waitForStackDelete()` — calls the module-private
`waitFor(valueProvider, timeout = 5000)`, polling `DescribeStacks` every
5s per in-flight stack to detect a terminal state, with no option
threading to it.

Programmatic consumers running large CI matrices who already slowed the
event monitor via `stackEventPollingInterval` saw `DescribeStacks` from
this stabilization loop become the dominant CloudFormation read-API
caller instead, still triggering throttling.

### Design decision: one parameter, not two

`stackEventPollingInterval` now governs both the event-polling and
stabilization-polling intervals, rather than adding a new sibling
parameter (e.g. `stackStabilizationPollingInterval`). Going with reuse
over a second parameter to avoid growing the public options surface on
`DeployOptions`/`DestroyOptions` for a distinction most consumers won't
need to control separately — both loops exist to reduce `DescribeStack*`
call volume against the same CloudFormation rate limit. Happy to split
it into a separate parameter in a follow-up if maintainers would rather
keep the two tunable independently.

### Changes

- Added an optional `stabilizationPollingInterval`/`pollingInterval`
parameter to `waitForStackDelete()`, `waitForStackDeploy()`, and
`stabilizeStack()` in `cfn-api.ts`. Default unchanged (5000ms).
- Threaded the existing `stackEventPollingInterval` option through to
that new parameter — it already sits right beside the
`waitForStackDeploy`/`waitForStackDelete` calls in `deploy-stack.ts`
(deploy, destroy, and the delete-before-recreate path).
- Threaded through:
- `deployStack()`/`destroyStack()` in `deploy-stack.ts` (all three call
sites: delete-before-recreate, post-deploy stabilization, post-destroy
stabilization)
- `Deployments.cleanupChangeSet()` (the change-set cleanup path, called
from `prepareStack()` and from `Toolkit.deploy()` when a user declines
the deploy confirmation prompt)
- Updated doc comments on `stackEventPollingInterval` at each layer
(`DeployOptions`, `DestroyOptions`, `DeployStackOptions` in both
`deploy-stack.ts` and `deployments.ts`) to note it also governs
stabilization polling.
- No public API surface changes — `stackEventPollingInterval` already
existed; only its scope of effect changed, and doc comments were updated
to reflect that.

### Not included

Per the issue, two call sites needed confirming during implementation:
- `waitForStackDelete` from `Deployments.cleanupChangeSet` —
**included** (see above).
- The rollback path (`Deployments.rollbackStack`), which calls
`stabilizeStack` directly — **deferred**. This is the same rollback
monitor that aws#1710 explicitly deferred for event polling, so leaving it
out here keeps this PR consistent with that scope. Happy to add
`stackEventPollingInterval` support to `RollbackStackOptions` in a
follow-up if maintainers want it included.

### Testing

- New `cfn-api-stabilization-polling-interval.test.ts`: directly
exercises `stabilizeStack`, `waitForStackDeploy`, and
`waitForStackDelete` with fake timers, asserting `DescribeStacks`
polling cadence at both the 5s default and a custom interval.
- Extended `deploy-stack-polling-interval.test.ts`: asserts
`deployStack()`/`destroyStack()` forward `stackEventPollingInterval` to
`waitForStackDeploy`/`waitForStackDelete` as the stabilization interval,
alongside the existing `StackActivityMonitor` assertions.
- Extended `cloudformation-deployments.test.ts`: asserts
`prepareStack()` forwards `stackEventPollingInterval` through
`cleanupChangeSet()` to `waitForStackDelete`.

---
By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache-2.0 license
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

toolkit-lib: make stack event polling interval configurable

4 participants