no-construct-stack-suffix
✅ Using recommended in an ESLint configuration enables this rule.
This rule disallows including the strings "Construct" or "Stack" in Construct IDs and Stack IDs.
Including "Construct" in a Construct ID (and similarly for "Stack" in a Stack ID) is discouraged because it can cause issues that should ideally be contained within the CDK environment to leak into the CloudFormation template and the broader AWS environment.
🔧 How to use
ts
// eslint.config.mjs
export default defineConfig([
{
// ... some configs
rules: {
"awscdk/no-construct-stack-suffix": "error",
},
},
]);✅ Correct Example
ts
import { Construct } from "constructs";
import { Bucket } from "aws-cdk-lib/aws-s3";
export class MyConstruct extends Construct {
constructor(scope: Construct, id: string) {
super(scope, id);
// ✅ Allowed if the "Construct" and "Stack" suffix are not appended
const bucket = new Bucket(this, "MyBucket");
}
}❌ Incorrect Example
ts
import { Construct } from "constructs";
import { Bucket } from "aws-cdk-lib/aws-s3";
import { Stack } from "aws-cdk-lib";
export class MyConstruct extends Construct {
constructor(scope: Construct, id: string) {
super(scope, id);
// ❌ Should not use the "Construct" suffix
const bucket = new Bucket(this, "BucketConstruct");
// ❌ Should not use the suffix "Stack"
new Stack(this, "MyStack");
}
}Options
ts
type Options = {
disallowedSuffixes: Array<"Construct" | "Stack">;
};
const defaultOptions: Options = {
disallowedSuffixes: ["Construct", "Stack"],
};disallowedSuffixes
An array of suffixes to disallow. Can include "Construct", "Stack", or both.
With: { disallowedSuffixes: ["Construct"] }
✅ Correct Example
ts
import { Construct } from "constructs";
import { Bucket } from "aws-cdk-lib/aws-s3";
export class MyConstruct extends Construct {
constructor(scope: Construct, id: string) {
super(scope, id);
// ✅ Allowed if the "Construct" suffix are not appended
new Stack(this, "MyStack");
}
}❌ Incorrect Example
ts
import { Construct } from "constructs";
import { Bucket } from "aws-cdk-lib/aws-s3";
import { Stack } from "aws-cdk-lib";
export class MyConstruct extends Construct {
constructor(scope: Construct, id: string) {
super(scope, id);
// ❌ Should not use the "Construct" suffix
const bucket = new Bucket(this, "BucketConstruct");
}
}