cdk-preflight
Catch deploy-time CloudFormation failures at cdk synth time.
Some CloudFormation constraints are not expressed in resource provider schemas — they live only in documentation, in service API validation, or across multiple properties. Templates that violate them pass cdk synth, pass CloudFormation pre-deployment validation, and then fail minutes into a deployment, burning a rollback cycle.
cdk-preflight is a curated Rego rule pack for exactly those constraints. It injects the rules into the AWS CDK built-in CloudFormation validator (aws-cdk-lib >= 2.267.0), so violations surface at synth with construct-level traces — before you deploy.
Every bundled rule is backed by a fail/pass template pair, and the failure has been reproduced against real AWS (or is explicitly marked doc-only). Rules that the built-in validation engine already covers are deliberately not duplicated — a test suite enforces this.
Quick start
npm i -D cdk-preflight
npx cdk-preflight init # inserts Preflight.apply(app) into your CDK app
or add one line yourself:
import { Preflight } from 'cdk-preflight';
const app = new App();
Preflight.apply(app);
cdk synth then reports violations like:
WARNING idle_timeout.timeout_seconds is 5000 but must be between 1 and 4000 seconds (CloudFormation Validate)
MyStack/Alb (Alb) aws-cdk-lib.aws_elasticloadbalancingv2.CfnLoadBalancer
Acknowledge with 'CloudFormation-Validate::pf-elbv2-lb-idle-timeout-range'
Failing the build
By default findings are warnings (matching the CDK built-in validator behavior). To make violations fail cdk synth:
Preflight.apply(app, { enforce: true });
| Option | Default | Effect |
|---|---|---|
enforce |
false |
Violations of bundled rules fail synthesis instead of warning |
strict |
false |
With enforce: also fail on error-class findings (ERROR/FATAL, e.g. F3034) of the built-in validation engine itself, which the CDK currently downgrades to warnings |
exclude |
[] |
Rule ids to disable |
includeUpstreamPending |
true |
Include rules already proposed to the upstream engine but not yet merged |
Individual findings can also be suppressed with the CDK acknowledge mechanism shown in the warning text.
Bundled rules
See docs/rules.md for the generated rule table. Highlights:
- ELBv2:
idle_timeout/deregistration_delay/slow_startattribute ranges (stringly-typed Key/Value attributes are invisible to schema validation) - IAM: managed (6,144 chars) and inline (role/group/user) policy document size limits
- CloudFront:
MinTTL <= DefaultTTL <= MaxTTLordering, ACM certificates must live inus-east-1 - Step Functions:
StartAt/Next/Default/Choicesmust reference defined states - EC2: security group TCP/UDP port ranges and
FromPort <= ToPort
For AI agents
To add cdk-preflight to a CDK app:
npm i -D cdk-preflightnpx cdk-preflight init(finds the entry point viacdk.jsonand insertsPreflight.apply(app); use--dry-runto preview)- Run
cdk synthand read the warnings; each carries a rule id, a suggested fix, and a construct trace - If the user wants synthesis to fail on violations, change the call to
Preflight.apply(app, { enforce: true })
The machine-readable findings are written to cdk.out/validation-report.json when synthesizing with -c @aws-cdk/core:validationReportJson=true.
How it works
Preflight.apply() registers the rules with the CDK built-in CloudFormationValidatePlugin (the cloudformation-validate Rust/WASM engine that ships inside aws-cdk-lib). No extra binaries, no network access at synth time. In enforce mode the same engine is invoked through a dedicated validation plugin so that violations fail synthesis.
Constraints that can be expressed in schemas or generic engine rules are contributed upstream instead of living here; each rule's meta.yaml tracks its upstream status, and rules retire once the engine covers them.
Requirements
aws-cdk-lib>= 2.267.0 (the first release that bundles the built-in CloudFormation validator)
Contributing
Rule authoring, the verification gates (including real-deploy reproduction), and the test layout are documented in AGENTS.md — written for AI coding agents and humans alike.
License
Apache-2.0
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cdk_preflight-0.0.0.tar.gz.
File metadata
- Download URL: cdk_preflight-0.0.0.tar.gz
- Upload date:
- Size: 73.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.14.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
250f2cc8b34ae0674e11e5063b0a7061955f3d151dbd6f1ebdf96d0f28fd7016
|
|
| MD5 |
30e4e60e452ea0660f798ae064278fcd
|
|
| BLAKE2b-256 |
3c4527752fc113119716668d63547d8d9cc833c8b51be7a2c7ced315c69d40bb
|
Provenance
The following attestation bundles were made for cdk_preflight-0.0.0.tar.gz:
Publisher:
release.yml on badmintoncryer/cdk-preflight
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cdk_preflight-0.0.0.tar.gz -
Subject digest:
250f2cc8b34ae0674e11e5063b0a7061955f3d151dbd6f1ebdf96d0f28fd7016 - Sigstore transparency entry: 2675267651
- Sigstore integration time:
-
Permalink:
badmintoncryer/cdk-preflight@f5a097c2b97cd0862860aa4e15c1cbf2e09d33de -
Branch / Tag:
refs/heads/main - Owner: https://github.com/badmintoncryer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@f5a097c2b97cd0862860aa4e15c1cbf2e09d33de -
Trigger Event:
push
-
Statement type:
File details
Details for the file cdk_preflight-0.0.0-py3-none-any.whl.
File metadata
- Download URL: cdk_preflight-0.0.0-py3-none-any.whl
- Upload date:
- Size: 71.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.14.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c1d5dba0d164a5e62263739980164821050b18d8337fe70a1f3fc94aba86ff5
|
|
| MD5 |
4ac495ab1f955dba1f0465b790a70109
|
|
| BLAKE2b-256 |
45f8a534fe7a26dd6b207408d04da7b61b2afc0edb2e0924319be2363f781be6
|
Provenance
The following attestation bundles were made for cdk_preflight-0.0.0-py3-none-any.whl:
Publisher:
release.yml on badmintoncryer/cdk-preflight
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cdk_preflight-0.0.0-py3-none-any.whl -
Subject digest:
4c1d5dba0d164a5e62263739980164821050b18d8337fe70a1f3fc94aba86ff5 - Sigstore transparency entry: 2675267607
- Sigstore integration time:
-
Permalink:
badmintoncryer/cdk-preflight@f5a097c2b97cd0862860aa4e15c1cbf2e09d33de -
Branch / Tag:
refs/heads/main - Owner: https://github.com/badmintoncryer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@f5a097c2b97cd0862860aa4e15c1cbf2e09d33de -
Trigger Event:
push
-
Statement type: