Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(core): show counts of resources when stack is overflowing #20398

Merged
merged 2 commits into from
May 18, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion packages/@aws-cdk/core/lib/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,8 @@ export class Stack extends CoreConstruct implements ITaggable {
const numberOfResources = Object.keys(resources).length;

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

function count(xs: string[]): Record<string, number> {
const ret: Record<string, number> = {};
for (const x of xs) {
if (x in ret) {
ret[x] += 1;
} else {
ret[x] = 1;
}
}
return ret;
}

// These imports have to be at the end to prevent circular imports
import { CfnOutput } from './cfn-output';
import { addDependency } from './deps';
Expand Down