Skip to content

Commit 51d89f8

Browse files
authored
chore(core): show counts of resources when stack is overflowing (#20398)
This makes it easier to diagnose why you are overlowing the maximum of 500 resources. ---- ### All Submissions: * [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent bb625c8 commit 51d89f8

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

packages/@aws-cdk/core/lib/stack.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,8 @@ export class Stack extends CoreConstruct implements ITaggable {
791791
const numberOfResources = Object.keys(resources).length;
792792

793793
if (numberOfResources > this.maxResources) {
794-
throw new Error(`Number of resources in stack '${this.node.path}': ${numberOfResources} is greater than allowed maximum of ${this.maxResources}`);
794+
const counts = Object.entries(count(Object.values(resources).map((r: any) => `${r?.Type}`))).map(([type, c]) => `${type} (${c})`).join(', ');
795+
throw new Error(`Number of resources in stack '${this.node.path}': ${numberOfResources} is greater than allowed maximum of ${this.maxResources}: ${counts}`);
795796
} else if (numberOfResources >= (this.maxResources * 0.8)) {
796797
Annotations.of(this).addInfo(`Number of resources: ${numberOfResources} is approaching allowed maximum of ${this.maxResources}`);
797798
}
@@ -1357,6 +1358,18 @@ export interface ExportValueOptions {
13571358
readonly name?: string;
13581359
}
13591360

1361+
function count(xs: string[]): Record<string, number> {
1362+
const ret: Record<string, number> = {};
1363+
for (const x of xs) {
1364+
if (x in ret) {
1365+
ret[x] += 1;
1366+
} else {
1367+
ret[x] = 1;
1368+
}
1369+
}
1370+
return ret;
1371+
}
1372+
13601373
// These imports have to be at the end to prevent circular imports
13611374
import { CfnOutput } from './cfn-output';
13621375
import { addDependency } from './deps';

0 commit comments

Comments
 (0)