This library acts as a mentor to AWS CDK users, providing guidance and suggestions for better infrastructure coding practices. Inspired by cfn_nag.
This library uses Aspects and is executed during the prepare phase.
% npm install -D cdk-mentor
import * as cdk from 'aws-cdk-lib';
import * as sns from 'aws-cdk-lib/aws-sns';
import { TestStack } from '../lib/test-stack';
import { CdkMentor } from 'cdk-mentor';
const app = new cdk.App();
const stack = new TestStack(app, 'TestStack');
cdk.Aspects.of(app).add(new CdkMentor());
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as sns from 'aws-cdk-lib/aws-sns';
export class TestStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
new sns.Topic(this, 'testTopic'); // Construct ID is NOT PascalCase
}
}
% npx cdk synth -q
[Error at /TestStack/testTopic/Resource] [ERR:001]: Construct ID "testTopic"should be defined in PascalCase.
Found errors
- Recommends PascalCase for Construct IDs
- Avoid
Stack
orConstruct
in Construct IDs - Detecte strong cross-stack references