Skip to content

Commit c79e35e

Browse files
authored
fix(cli): requests get throttled when there is a large number of stacks (#927)
The CLI is making an unlimited number of concurrent `GetTemplate` requests. When there is a large number of stacks, CloudFormation may throttle the requests. Limit concurrency to 20. --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license
1 parent d1b4113 commit c79e35e

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

packages/@aws-cdk/toolkit-lib/lib/api/refactoring/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { ResourceLocation, ResourceMapping } from './cloudformation';
1515
import { hashObject } from './digest';
1616
import type { MappingGroup } from '../../actions';
1717
import { ToolkitError } from '../../toolkit/toolkit-error';
18+
import { pLimit } from '../../util/concurrency';
1819

1920
export * from './exclude';
2021
export * from './context';
@@ -144,8 +145,10 @@ export async function getDeployedStacks(
144145
};
145146
};
146147

148+
const limit = pLimit(20);
149+
147150
// eslint-disable-next-line @cdklabs/promiseall-no-unbounded-parallelism
148-
return Promise.all(summaries.map(normalize));
151+
return Promise.all(summaries.map(s => limit(() => normalize(s))));
149152
}
150153

151154
export function formatEnvironmentSectionHeader(environment: cxapi.Environment) {

packages/aws-cdk/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,7 @@ command to consider only a subset of them, you can specify the stacks you
11361136
want, both local and deployed:
11371137

11381138
```shell
1139-
$ cdk refactor --local-stack Foo --local-stack Bar --deployed-stack Foo --unstable=refactor --dry-run
1139+
$ cdk refactor Test* ProdStack --unstable=refactor --dry-run
11401140
```
11411141

11421142
This is useful if, for example, you have more than one CDK application deployed

0 commit comments

Comments
 (0)