cdk-preflight 0.0.53__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cdk_preflight/__init__.py +363 -0
- cdk_preflight/_jsii/__init__.py +28 -0
- cdk_preflight/_jsii/cdk-preflight@0.0.53.jsii.tgz +0 -0
- cdk_preflight/py.typed +1 -0
- cdk_preflight-0.0.53.data/scripts/cdk-preflight +17 -0
- cdk_preflight-0.0.53.data/scripts/cdkpf +15 -0
- cdk_preflight-0.0.53.dist-info/LICENSE +202 -0
- cdk_preflight-0.0.53.dist-info/METADATA +171 -0
- cdk_preflight-0.0.53.dist-info/RECORD +11 -0
- cdk_preflight-0.0.53.dist-info/WHEEL +5 -0
- cdk_preflight-0.0.53.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
r'''
|
|
2
|
+
<p align="center">
|
|
3
|
+
<img src="https://raw.githubusercontent.com/badmintoncryer/cdk-preflight/main/assets/logo.png" alt="cdk-preflight" width="104" height="104">
|
|
4
|
+
</p><h1 align="center">cdk-preflight</h1><p align="center">
|
|
5
|
+
<strong>Catch deploy-time CloudFormation failures at <code>cdk synth</code> time.</strong>
|
|
6
|
+
</p><p align="center">
|
|
7
|
+
<a href="https://github.com/badmintoncryer/cdk-preflight/actions/workflows/monthly-verify.yml"><img src="https://github.com/badmintoncryer/cdk-preflight/actions/workflows/monthly-verify.yml/badge.svg" alt="monthly real-deploy verification"></a>
|
|
8
|
+
<a href="https://www.npmjs.com/package/cdk-preflight"><img src="https://img.shields.io/npm/v/cdk-preflight.svg" alt="npm version"></a>
|
|
9
|
+
<a href="https://www.npmjs.com/package/cdk-preflight"><img src="https://img.shields.io/npm/dt/cdk-preflight.svg" alt="npm total downloads"></a>
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
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.
|
|
13
|
+
|
|
14
|
+
cdk-preflight is a curated [Rego rule pack](docs/rules.md) for exactly those constraints, evaluated with the CloudFormation validation engine that ships inside `aws-cdk-lib` (>= 2.267.0). By default a violation **fails `cdk synth`** — a template that is known to fail at deploy time never leaves your machine.
|
|
15
|
+
|
|
16
|
+
The pack aims at **every deploy-time failure that no existing CDK mechanism already catches** — nothing narrower. 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.
|
|
17
|
+
|
|
18
|
+
> **Requires `aws-cdk-lib` >= 2.267.0** (released 2026-08-27) — the first release that bundles
|
|
19
|
+
> the CloudFormation validation engine. On older versions the rules cannot run at all.
|
|
20
|
+
|
|
21
|
+
## Quick start
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm i -D cdk-preflight
|
|
25
|
+
npx cdkpf init # inserts Preflight.apply(app) into your CDK app
|
|
26
|
+
# (`npx cdkpf init` is the same command, shorter)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
or add one line yourself:
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
import { Preflight } from 'cdk-preflight';
|
|
33
|
+
|
|
34
|
+
const app = new App();
|
|
35
|
+
Preflight.apply(app);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
On violation, `cdk synth` fails with one error per finding, including the construct trace:
|
|
39
|
+
|
|
40
|
+
```text
|
|
41
|
+
ERROR idle_timeout.timeout_seconds is 5000 but must be between 1 and 4000 seconds (cdk-preflight)
|
|
42
|
+
MyStack/Alb/Resource (Alb16C2F182) aws-cdk-lib.aws_elasticloadbalancingv2.CfnLoadBalancer
|
|
43
|
+
|
|
44
|
+
Synthesis finished with errors
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Observe-only mode
|
|
48
|
+
|
|
49
|
+
To roll the rules out gradually, start with `enforce: false`: findings then surface as synth **warnings** through the CDK built-in validator, with construct traces and per-finding acknowledgement:
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
Preflight.apply(app, { enforce: false });
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```text
|
|
56
|
+
WARNING idle_timeout.timeout_seconds is 5000 but must be between 1 and 4000 seconds (CloudFormation Validate)
|
|
57
|
+
MyStack/Alb (Alb) aws-cdk-lib.aws_elasticloadbalancingv2.CfnLoadBalancer
|
|
58
|
+
Acknowledge with 'CloudFormation-Validate::pf-elbv2-lb-idle-timeout-range'
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
> **Known limitation with stages.** The AWS CDK CLI drops validation findings for stacks nested in a `Stage`
|
|
62
|
+
> before printing them, so in observe-only mode those findings appear **only** in `cdk.out/validation-report.json`
|
|
63
|
+
> and never on the console. Enforce mode is not affected: cdk-preflight reports such findings itself and fails
|
|
64
|
+
> synthesis. This is a CLI-side bug (present since aws-cdk 2.1128.1), not a rule evaluation problem.
|
|
65
|
+
|
|
66
|
+
| Option | Default | Effect |
|
|
67
|
+
|---|---|---|
|
|
68
|
+
| `enforce` | `true` | Violations of bundled rules fail synthesis; set to `false` to only warn |
|
|
69
|
+
| `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 |
|
|
70
|
+
| `exclude` | `[]` | Rule ids to disable |
|
|
71
|
+
| `includeUpstreamPending` | `true` | Include rules already proposed to the upstream engine but not yet merged |
|
|
72
|
+
|
|
73
|
+
To opt out of a single rule, pass its id in `exclude`. In observe-only mode, individual findings can also be suppressed with the CDK acknowledge mechanism shown in the warning text.
|
|
74
|
+
|
|
75
|
+
## Bundled rules
|
|
76
|
+
|
|
77
|
+
See [docs/rules.md](docs/rules.md) for the generated rule table. Highlights:
|
|
78
|
+
|
|
79
|
+
* **ELBv2**: `idle_timeout` / `deregistration_delay` / `slow_start` attribute ranges (stringly-typed Key/Value attributes are invisible to schema validation)
|
|
80
|
+
* **IAM**: managed (6,144 chars) and inline (role/group/user) policy document size limits
|
|
81
|
+
* **CloudFront**: `MinTTL <= DefaultTTL <= MaxTTL` ordering, ACM certificates must live in `us-east-1`
|
|
82
|
+
* **Step Functions**: `Next`/`Default`/`Choices` must reference defined states (a dangling `StartAt` is already caught by the engine's built-in `E3601`)
|
|
83
|
+
* **EC2**: security group TCP/UDP port ranges and `FromPort <= ToPort`
|
|
84
|
+
|
|
85
|
+
## For AI agents
|
|
86
|
+
|
|
87
|
+
To add cdk-preflight to a CDK app:
|
|
88
|
+
|
|
89
|
+
1. `npm i -D cdk-preflight`
|
|
90
|
+
2. `npx cdk-preflight init` — or the shorter alias `npx cdkpf init` (finds the entry point via `cdk.json` and inserts `Preflight.apply(app)`; use `--dry-run` to preview)
|
|
91
|
+
3. Run `cdk synth`. Violations fail the synth with a validation report; each finding carries a rule id, the actual value, and a suggested fix
|
|
92
|
+
4. To fix a finding, prefer correcting the resource. To opt out instead: `exclude: ['<rule-id>']` disables one rule, `enforce: false` switches to warn-only reporting
|
|
93
|
+
|
|
94
|
+
The machine-readable findings are written to `cdk.out/validation-report.json` when synthesizing with `-c @aws-cdk/core:validationReportJson=true`.
|
|
95
|
+
|
|
96
|
+
### Report missed deploy errors
|
|
97
|
+
|
|
98
|
+
cdk-preflight only knows the failure modes it has benched. When a deploy fails on a constraint the pack should have caught, that report is how new rules get added — but at that moment cdk-preflight is out of the loop (it passed the synth), so the instruction has to already sit in your agent's context. Paste this into your repository's `AGENTS.md` (or `CLAUDE.md`):
|
|
99
|
+
|
|
100
|
+
```markdown
|
|
101
|
+
## cdk-preflight: report missed deploy errors
|
|
102
|
+
|
|
103
|
+
If `cdk deploy` fails even though `cdk synth` (with cdk-preflight enabled) passed,
|
|
104
|
+
and the failure is a service-side validation rejection — CREATE_FAILED/UPDATE_FAILED
|
|
105
|
+
with a 400-class message such as "Invalid request provided: ..." — cdk-preflight is
|
|
106
|
+
missing a rule. Report it:
|
|
107
|
+
|
|
108
|
+
1. Qualify first. NOT reportable: AccessDenied / permissions, service quotas,
|
|
109
|
+
throttling, name conflicts with existing resources, stabilization timeouts.
|
|
110
|
+
2. Redact account-specific data (account IDs -> 123456789012, real ARNs/domains
|
|
111
|
+
-> placeholders).
|
|
112
|
+
3. Search existing issues: https://github.com/badmintoncryer/cdk-preflight/issues
|
|
113
|
+
4. With your user's approval, open a "Missed deploy error" issue with the verbatim
|
|
114
|
+
error message, the resource type, a minimal template snippet, and your
|
|
115
|
+
aws-cdk-lib / cdk-preflight versions.
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Scope and rule lifecycle
|
|
119
|
+
|
|
120
|
+
A constraint belongs in the pack when violating it makes a real deployment fail *and* no layer that sees the same synthesized template already blocks it. There is no further "is this worth a rule" question — if the gap is real, it gets a rule.
|
|
121
|
+
|
|
122
|
+
CDK L2 construct validation is deliberately **not** one of those layers. `CfnXxx` usage, escape hatches, `addPropertyOverride`, `cloudformation-include` and migrated templates all bypass L2, so an L2 guard covering the same mistake neither disqualifies a rule nor retires one.
|
|
123
|
+
|
|
124
|
+
That makes growth the normal state, and it has a consequence worth knowing before you upgrade: **new rules land in minor releases, so a minor upgrade can newly fail a `cdk synth` that passed yesterday.** That is intended, not a regression. If you need a frozen rule set, pin the version; to drop a single rule, `exclude: ['<rule-id>']`; to see everything without failing the build, `enforce: false`.
|
|
125
|
+
|
|
126
|
+
Rules move the other way too. Once the validation engine bundled in `aws-cdk-lib` (or CloudFormation's own pre-deploy validation) starts blocking a constraint, the rule is deleted rather than kept as a duplicate — staying on an older `aws-cdk-lib` and an older cdk-preflight keeps the old behavior.
|
|
127
|
+
|
|
128
|
+
## How it works
|
|
129
|
+
|
|
130
|
+
`Preflight.apply()` evaluates the rules with the [cloudformation-validate](https://github.com/aws-cloudformation/cloudformation-validate) Rust/WASM engine that ships inside `aws-cdk-lib` — no extra binaries, no network access at synth time. In the default enforce mode the engine is invoked through a dedicated CDK validation plugin so that violations fail synthesis; with `enforce: false` the rules are instead injected into the CDK built-in `CloudFormationValidatePlugin` and reported as warnings.
|
|
131
|
+
|
|
132
|
+
Constraints that *can* be expressed in schemas or generic engine rules also make good upstream PRs to that engine, but nothing here waits on one — the upstream release cycle is deliberately slower than this pack's. Each rule's `meta.yaml` tracks its upstream status so that retirement stays bookkeeping.
|
|
133
|
+
|
|
134
|
+
## Requirements
|
|
135
|
+
|
|
136
|
+
* `aws-cdk-lib` >= 2.267.0, released 2026-08-27 (the first release that bundles the built-in CloudFormation validator). This is a recent release — an existing CDK app may need an upgrade before cdk-preflight can run.
|
|
137
|
+
|
|
138
|
+
## Contributing
|
|
139
|
+
|
|
140
|
+
Rule authoring, the verification gates (including real-deploy reproduction), and the test layout are documented in [AGENTS.md](AGENTS.md) — written for AI coding agents and humans alike.
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
Apache-2.0
|
|
145
|
+
'''
|
|
146
|
+
from __future__ import annotations
|
|
147
|
+
|
|
148
|
+
from pkgutil import extend_path
|
|
149
|
+
__path__ = extend_path(__path__, __name__)
|
|
150
|
+
|
|
151
|
+
import abc
|
|
152
|
+
import builtins
|
|
153
|
+
import datetime
|
|
154
|
+
import enum
|
|
155
|
+
import typing
|
|
156
|
+
|
|
157
|
+
import jsii
|
|
158
|
+
import publication
|
|
159
|
+
import typing_extensions
|
|
160
|
+
|
|
161
|
+
from jsii._type_checking import cached_type_hints, check_type
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
from ._jsii import *
|
|
165
|
+
|
|
166
|
+
class _LazyImport:
|
|
167
|
+
def __init__(self, module_name: str) -> None:
|
|
168
|
+
self._module_name = module_name
|
|
169
|
+
self._module: typing.Any = None
|
|
170
|
+
def __getattr__(self, name: str) -> typing.Any:
|
|
171
|
+
if self._module is None:
|
|
172
|
+
import importlib
|
|
173
|
+
self._module = importlib.import_module(self._module_name)
|
|
174
|
+
return getattr(self._module, name)
|
|
175
|
+
|
|
176
|
+
if typing.TYPE_CHECKING:
|
|
177
|
+
|
|
178
|
+
import constructs as _constructs_77d1e7e8
|
|
179
|
+
else:
|
|
180
|
+
|
|
181
|
+
_constructs_77d1e7e8 = _LazyImport("constructs")
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
class Preflight(metaclass=jsii.JSIIMeta, jsii_type="cdk-preflight.Preflight"):
|
|
185
|
+
'''cdk-preflight: catch deploy-time CloudFormation failures at synth time.
|
|
186
|
+
|
|
187
|
+
Injects a curated Rego rule pack (constraints that resource provider schemas
|
|
188
|
+
do not express: doc-only value limits, cross-property and cross-resource
|
|
189
|
+
rules) into the AWS CDK built-in CloudFormation validator.
|
|
190
|
+
|
|
191
|
+
Example::
|
|
192
|
+
|
|
193
|
+
declare const app: App;
|
|
194
|
+
Preflight.apply(app);
|
|
195
|
+
'''
|
|
196
|
+
|
|
197
|
+
@jsii.member(jsii_name="apply")
|
|
198
|
+
@builtins.classmethod
|
|
199
|
+
def apply(
|
|
200
|
+
cls,
|
|
201
|
+
scope: "_constructs_77d1e7e8.IConstruct",
|
|
202
|
+
*,
|
|
203
|
+
enforce: typing.Optional[builtins.bool] = None,
|
|
204
|
+
exclude: typing.Optional[typing.Sequence[builtins.str]] = None,
|
|
205
|
+
include_upstream_pending: typing.Optional[builtins.bool] = None,
|
|
206
|
+
strict: typing.Optional[builtins.bool] = None,
|
|
207
|
+
) -> None:
|
|
208
|
+
'''Register the cdk-preflight rules on an App or Stage.
|
|
209
|
+
|
|
210
|
+
:param scope: -
|
|
211
|
+
:param enforce: Fail synthesis when a bundled rule is violated. In the default (enforce) mode, cdk-preflight evaluates its rules with its own validation plugin and a violation makes ``cdk synth`` fail — the whole point of preflight checks is that a template known to fail at deploy time never leaves your machine. Set ``enforce: false`` to observe first: findings are then reported through the CDK built-in CloudFormation validator and surface as synth warnings with construct traces, which can be muted per finding via ``Acknowledge with 'CloudFormation-Validate::<rule-id>'``. Default: true
|
|
212
|
+
:param exclude: Rule ids to disable (see ``Preflight.ruleIds()`` or docs/rules.md). Default: - all bundled rules are enabled
|
|
213
|
+
:param include_upstream_pending: Include rules that are marked ``pending-engine`` (candidates that have been proposed to the upstream cloudformation-validate engine but are not merged yet). Disable this if you run a newer engine that already covers them. Default: true
|
|
214
|
+
:param strict: In enforce mode, additionally fail synthesis on error-class findings (severity ERROR/FATAL) of the built-in validation engine itself, e.g. schema violations like ``F3034``. This is the workaround for the CDK behavior where all built-in findings are downgraded to warnings. Only effective in enforce mode (the default). Default: false
|
|
215
|
+
'''
|
|
216
|
+
if __debug__:
|
|
217
|
+
type_hints = cached_type_hints(_typecheckingstub__5b535ea6056dfabd62239bba1185a75fb43155b62d18b3cbb69ca8a01b7edfa8)
|
|
218
|
+
check_type(argname="argument scope", value=scope, expected_type=type_hints["scope"])
|
|
219
|
+
options = PreflightOptions(
|
|
220
|
+
enforce=enforce,
|
|
221
|
+
exclude=exclude,
|
|
222
|
+
include_upstream_pending=include_upstream_pending,
|
|
223
|
+
strict=strict,
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
return typing.cast(None, jsii.sinvoke(cls, "apply", [scope, options]))
|
|
227
|
+
|
|
228
|
+
@jsii.member(jsii_name="ruleIds")
|
|
229
|
+
@builtins.classmethod
|
|
230
|
+
def rule_ids(cls) -> typing.List[builtins.str]:
|
|
231
|
+
'''The ids of all bundled rules.'''
|
|
232
|
+
return typing.cast(typing.List[builtins.str], jsii.sinvoke(cls, "ruleIds", []))
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
@jsii.data_type(
|
|
236
|
+
jsii_type="cdk-preflight.PreflightOptions",
|
|
237
|
+
jsii_struct_bases=[],
|
|
238
|
+
name_mapping={
|
|
239
|
+
"enforce": "enforce",
|
|
240
|
+
"exclude": "exclude",
|
|
241
|
+
"include_upstream_pending": "includeUpstreamPending",
|
|
242
|
+
"strict": "strict",
|
|
243
|
+
},
|
|
244
|
+
)
|
|
245
|
+
class PreflightOptions:
|
|
246
|
+
def __init__(
|
|
247
|
+
self,
|
|
248
|
+
*,
|
|
249
|
+
enforce: typing.Optional[builtins.bool] = None,
|
|
250
|
+
exclude: typing.Optional[typing.Sequence[builtins.str]] = None,
|
|
251
|
+
include_upstream_pending: typing.Optional[builtins.bool] = None,
|
|
252
|
+
strict: typing.Optional[builtins.bool] = None,
|
|
253
|
+
) -> None:
|
|
254
|
+
'''Options for {@link Preflight.apply}.
|
|
255
|
+
|
|
256
|
+
:param enforce: Fail synthesis when a bundled rule is violated. In the default (enforce) mode, cdk-preflight evaluates its rules with its own validation plugin and a violation makes ``cdk synth`` fail — the whole point of preflight checks is that a template known to fail at deploy time never leaves your machine. Set ``enforce: false`` to observe first: findings are then reported through the CDK built-in CloudFormation validator and surface as synth warnings with construct traces, which can be muted per finding via ``Acknowledge with 'CloudFormation-Validate::<rule-id>'``. Default: true
|
|
257
|
+
:param exclude: Rule ids to disable (see ``Preflight.ruleIds()`` or docs/rules.md). Default: - all bundled rules are enabled
|
|
258
|
+
:param include_upstream_pending: Include rules that are marked ``pending-engine`` (candidates that have been proposed to the upstream cloudformation-validate engine but are not merged yet). Disable this if you run a newer engine that already covers them. Default: true
|
|
259
|
+
:param strict: In enforce mode, additionally fail synthesis on error-class findings (severity ERROR/FATAL) of the built-in validation engine itself, e.g. schema violations like ``F3034``. This is the workaround for the CDK behavior where all built-in findings are downgraded to warnings. Only effective in enforce mode (the default). Default: false
|
|
260
|
+
'''
|
|
261
|
+
if __debug__:
|
|
262
|
+
type_hints = cached_type_hints(_typecheckingstub__12ab0dc6052d00feef3e218547f7a8add8c0a9bd629d0362a30a71aa52b7cab1)
|
|
263
|
+
check_type(argname="argument enforce", value=enforce, expected_type=type_hints["enforce"])
|
|
264
|
+
check_type(argname="argument exclude", value=exclude, expected_type=type_hints["exclude"])
|
|
265
|
+
check_type(argname="argument include_upstream_pending", value=include_upstream_pending, expected_type=type_hints["include_upstream_pending"])
|
|
266
|
+
check_type(argname="argument strict", value=strict, expected_type=type_hints["strict"])
|
|
267
|
+
self._values: typing.Dict[builtins.str, typing.Any] = {}
|
|
268
|
+
if enforce is not None:
|
|
269
|
+
self._values["enforce"] = enforce
|
|
270
|
+
if exclude is not None:
|
|
271
|
+
self._values["exclude"] = exclude
|
|
272
|
+
if include_upstream_pending is not None:
|
|
273
|
+
self._values["include_upstream_pending"] = include_upstream_pending
|
|
274
|
+
if strict is not None:
|
|
275
|
+
self._values["strict"] = strict
|
|
276
|
+
|
|
277
|
+
@builtins.property
|
|
278
|
+
def enforce(self) -> typing.Optional[builtins.bool]:
|
|
279
|
+
'''Fail synthesis when a bundled rule is violated.
|
|
280
|
+
|
|
281
|
+
In the default (enforce) mode, cdk-preflight evaluates its rules with its
|
|
282
|
+
own validation plugin and a violation makes ``cdk synth`` fail — the whole
|
|
283
|
+
point of preflight checks is that a template known to fail at deploy time
|
|
284
|
+
never leaves your machine. Set ``enforce: false`` to observe first: findings
|
|
285
|
+
are then reported through the CDK built-in CloudFormation validator and
|
|
286
|
+
surface as synth warnings with construct traces, which can be muted per
|
|
287
|
+
finding via ``Acknowledge with 'CloudFormation-Validate::<rule-id>'``.
|
|
288
|
+
|
|
289
|
+
:default: true
|
|
290
|
+
'''
|
|
291
|
+
result = self._values.get("enforce")
|
|
292
|
+
return typing.cast(typing.Optional[builtins.bool], result)
|
|
293
|
+
|
|
294
|
+
@builtins.property
|
|
295
|
+
def exclude(self) -> typing.Optional[typing.List[builtins.str]]:
|
|
296
|
+
'''Rule ids to disable (see ``Preflight.ruleIds()`` or docs/rules.md).
|
|
297
|
+
|
|
298
|
+
:default: - all bundled rules are enabled
|
|
299
|
+
'''
|
|
300
|
+
result = self._values.get("exclude")
|
|
301
|
+
return typing.cast(typing.Optional[typing.List[builtins.str]], result)
|
|
302
|
+
|
|
303
|
+
@builtins.property
|
|
304
|
+
def include_upstream_pending(self) -> typing.Optional[builtins.bool]:
|
|
305
|
+
'''Include rules that are marked ``pending-engine`` (candidates that have been proposed to the upstream cloudformation-validate engine but are not merged yet).
|
|
306
|
+
|
|
307
|
+
Disable this if you run a newer engine that already covers them.
|
|
308
|
+
|
|
309
|
+
:default: true
|
|
310
|
+
'''
|
|
311
|
+
result = self._values.get("include_upstream_pending")
|
|
312
|
+
return typing.cast(typing.Optional[builtins.bool], result)
|
|
313
|
+
|
|
314
|
+
@builtins.property
|
|
315
|
+
def strict(self) -> typing.Optional[builtins.bool]:
|
|
316
|
+
'''In enforce mode, additionally fail synthesis on error-class findings (severity ERROR/FATAL) of the built-in validation engine itself, e.g. schema violations like ``F3034``. This is the workaround for the CDK behavior where all built-in findings are downgraded to warnings.
|
|
317
|
+
|
|
318
|
+
Only effective in enforce mode (the default).
|
|
319
|
+
|
|
320
|
+
:default: false
|
|
321
|
+
'''
|
|
322
|
+
result = self._values.get("strict")
|
|
323
|
+
return typing.cast(typing.Optional[builtins.bool], result)
|
|
324
|
+
|
|
325
|
+
def __eq__(self, rhs: typing.Any) -> builtins.bool:
|
|
326
|
+
return isinstance(rhs, self.__class__) and rhs._values == self._values
|
|
327
|
+
|
|
328
|
+
def __ne__(self, rhs: typing.Any) -> builtins.bool:
|
|
329
|
+
return not (rhs == self)
|
|
330
|
+
|
|
331
|
+
def __repr__(self) -> str:
|
|
332
|
+
return "PreflightOptions(%s)" % ", ".join(
|
|
333
|
+
k + "=" + repr(v) for k, v in self._values.items()
|
|
334
|
+
)
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
__all__ = [
|
|
338
|
+
"Preflight",
|
|
339
|
+
"PreflightOptions",
|
|
340
|
+
]
|
|
341
|
+
|
|
342
|
+
publication.publish()
|
|
343
|
+
|
|
344
|
+
def _typecheckingstub__5b535ea6056dfabd62239bba1185a75fb43155b62d18b3cbb69ca8a01b7edfa8(
|
|
345
|
+
scope: _constructs_77d1e7e8.IConstruct,
|
|
346
|
+
*,
|
|
347
|
+
enforce: typing.Optional[builtins.bool] = None,
|
|
348
|
+
exclude: typing.Optional[typing.Sequence[builtins.str]] = None,
|
|
349
|
+
include_upstream_pending: typing.Optional[builtins.bool] = None,
|
|
350
|
+
strict: typing.Optional[builtins.bool] = None,
|
|
351
|
+
) -> None:
|
|
352
|
+
"""Type checking stubs"""
|
|
353
|
+
pass
|
|
354
|
+
|
|
355
|
+
def _typecheckingstub__12ab0dc6052d00feef3e218547f7a8add8c0a9bd629d0362a30a71aa52b7cab1(
|
|
356
|
+
*,
|
|
357
|
+
enforce: typing.Optional[builtins.bool] = None,
|
|
358
|
+
exclude: typing.Optional[typing.Sequence[builtins.str]] = None,
|
|
359
|
+
include_upstream_pending: typing.Optional[builtins.bool] = None,
|
|
360
|
+
strict: typing.Optional[builtins.bool] = None,
|
|
361
|
+
) -> None:
|
|
362
|
+
"""Type checking stubs"""
|
|
363
|
+
pass
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from pkgutil import extend_path
|
|
2
|
+
__path__ = extend_path(__path__, __name__)
|
|
3
|
+
|
|
4
|
+
import abc
|
|
5
|
+
import builtins
|
|
6
|
+
import datetime
|
|
7
|
+
import enum
|
|
8
|
+
import typing
|
|
9
|
+
|
|
10
|
+
import jsii
|
|
11
|
+
import publication
|
|
12
|
+
import typing_extensions
|
|
13
|
+
|
|
14
|
+
from jsii._type_checking import cached_type_hints, check_type
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
import aws_cdk._jsii
|
|
18
|
+
import constructs._jsii
|
|
19
|
+
|
|
20
|
+
__jsii_assembly__ = jsii.JSIIAssembly.load(
|
|
21
|
+
"cdk-preflight", "0.0.53", __name__[0:-6], "cdk-preflight@0.0.53.jsii.tgz"
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
__all__ = [
|
|
25
|
+
"__jsii_assembly__",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
publication.publish()
|
|
Binary file
|
cdk_preflight/py.typed
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!python
|
|
2
|
+
|
|
3
|
+
import jsii
|
|
4
|
+
import sys
|
|
5
|
+
import os
|
|
6
|
+
|
|
7
|
+
if "JSII_RUNTIME_PACKAGE_CACHE" not in os.environ:
|
|
8
|
+
os.environ["JSII_RUNTIME_PACKAGE_CACHE"] = "disabled"
|
|
9
|
+
|
|
10
|
+
__jsii_assembly__ = jsii.JSIIAssembly.load(
|
|
11
|
+
"cdk-preflight", "0.0.53", "cdk_preflight", "cdk-preflight@0.0.53.jsii.tgz"
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
exit_code = __jsii_assembly__.invokeBinScript(
|
|
15
|
+
"cdk-preflight", "cdk-preflight", sys.argv[1:]
|
|
16
|
+
)
|
|
17
|
+
exit(exit_code)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!python
|
|
2
|
+
|
|
3
|
+
import jsii
|
|
4
|
+
import sys
|
|
5
|
+
import os
|
|
6
|
+
|
|
7
|
+
if "JSII_RUNTIME_PACKAGE_CACHE" not in os.environ:
|
|
8
|
+
os.environ["JSII_RUNTIME_PACKAGE_CACHE"] = "disabled"
|
|
9
|
+
|
|
10
|
+
__jsii_assembly__ = jsii.JSIIAssembly.load(
|
|
11
|
+
"cdk-preflight", "0.0.53", "cdk_preflight", "cdk-preflight@0.0.53.jsii.tgz"
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
exit_code = __jsii_assembly__.invokeBinScript("cdk-preflight", "cdkpf", sys.argv[1:])
|
|
15
|
+
exit(exit_code)
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: cdk-preflight
|
|
3
|
+
Version: 0.0.53
|
|
4
|
+
Summary: Catch deploy-time CloudFormation failures at synth time: a Rego rule pack for constraints that resource schemas miss, injected into the AWS CDK built-in validator
|
|
5
|
+
Home-page: https://github.com/badmintoncryer/cdk-preflight.git
|
|
6
|
+
Author: Kazuho CryerShinozuka<malaysia.cryer@gmail.com>
|
|
7
|
+
License: Apache-2.0
|
|
8
|
+
Project-URL: Source, https://github.com/badmintoncryer/cdk-preflight.git
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Programming Language :: JavaScript
|
|
12
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
20
|
+
Classifier: License :: OSI Approved
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: aws-cdk-lib <3.0.0,>=2.267.0
|
|
25
|
+
Requires-Dist: constructs <11.0.0,>=10.5.1
|
|
26
|
+
Requires-Dist: jsii <2.0.0,>=1.140.0
|
|
27
|
+
Requires-Dist: publication >=0.0.3
|
|
28
|
+
|
|
29
|
+
<p align="center">
|
|
30
|
+
<img src="https://raw.githubusercontent.com/badmintoncryer/cdk-preflight/main/assets/logo.png" alt="cdk-preflight" width="104" height="104">
|
|
31
|
+
</p><h1 align="center">cdk-preflight</h1><p align="center">
|
|
32
|
+
<strong>Catch deploy-time CloudFormation failures at <code>cdk synth</code> time.</strong>
|
|
33
|
+
</p><p align="center">
|
|
34
|
+
<a href="https://github.com/badmintoncryer/cdk-preflight/actions/workflows/monthly-verify.yml"><img src="https://github.com/badmintoncryer/cdk-preflight/actions/workflows/monthly-verify.yml/badge.svg" alt="monthly real-deploy verification"></a>
|
|
35
|
+
<a href="https://www.npmjs.com/package/cdk-preflight"><img src="https://img.shields.io/npm/v/cdk-preflight.svg" alt="npm version"></a>
|
|
36
|
+
<a href="https://www.npmjs.com/package/cdk-preflight"><img src="https://img.shields.io/npm/dt/cdk-preflight.svg" alt="npm total downloads"></a>
|
|
37
|
+
</p>
|
|
38
|
+
|
|
39
|
+
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.
|
|
40
|
+
|
|
41
|
+
cdk-preflight is a curated [Rego rule pack](docs/rules.md) for exactly those constraints, evaluated with the CloudFormation validation engine that ships inside `aws-cdk-lib` (>= 2.267.0). By default a violation **fails `cdk synth`** — a template that is known to fail at deploy time never leaves your machine.
|
|
42
|
+
|
|
43
|
+
The pack aims at **every deploy-time failure that no existing CDK mechanism already catches** — nothing narrower. 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.
|
|
44
|
+
|
|
45
|
+
> **Requires `aws-cdk-lib` >= 2.267.0** (released 2026-08-27) — the first release that bundles
|
|
46
|
+
> the CloudFormation validation engine. On older versions the rules cannot run at all.
|
|
47
|
+
|
|
48
|
+
## Quick start
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npm i -D cdk-preflight
|
|
52
|
+
npx cdkpf init # inserts Preflight.apply(app) into your CDK app
|
|
53
|
+
# (`npx cdkpf init` is the same command, shorter)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
or add one line yourself:
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
import { Preflight } from 'cdk-preflight';
|
|
60
|
+
|
|
61
|
+
const app = new App();
|
|
62
|
+
Preflight.apply(app);
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
On violation, `cdk synth` fails with one error per finding, including the construct trace:
|
|
66
|
+
|
|
67
|
+
```text
|
|
68
|
+
ERROR idle_timeout.timeout_seconds is 5000 but must be between 1 and 4000 seconds (cdk-preflight)
|
|
69
|
+
MyStack/Alb/Resource (Alb16C2F182) aws-cdk-lib.aws_elasticloadbalancingv2.CfnLoadBalancer
|
|
70
|
+
|
|
71
|
+
Synthesis finished with errors
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Observe-only mode
|
|
75
|
+
|
|
76
|
+
To roll the rules out gradually, start with `enforce: false`: findings then surface as synth **warnings** through the CDK built-in validator, with construct traces and per-finding acknowledgement:
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
Preflight.apply(app, { enforce: false });
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
```text
|
|
83
|
+
WARNING idle_timeout.timeout_seconds is 5000 but must be between 1 and 4000 seconds (CloudFormation Validate)
|
|
84
|
+
MyStack/Alb (Alb) aws-cdk-lib.aws_elasticloadbalancingv2.CfnLoadBalancer
|
|
85
|
+
Acknowledge with 'CloudFormation-Validate::pf-elbv2-lb-idle-timeout-range'
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
> **Known limitation with stages.** The AWS CDK CLI drops validation findings for stacks nested in a `Stage`
|
|
89
|
+
> before printing them, so in observe-only mode those findings appear **only** in `cdk.out/validation-report.json`
|
|
90
|
+
> and never on the console. Enforce mode is not affected: cdk-preflight reports such findings itself and fails
|
|
91
|
+
> synthesis. This is a CLI-side bug (present since aws-cdk 2.1128.1), not a rule evaluation problem.
|
|
92
|
+
|
|
93
|
+
| Option | Default | Effect |
|
|
94
|
+
|---|---|---|
|
|
95
|
+
| `enforce` | `true` | Violations of bundled rules fail synthesis; set to `false` to only warn |
|
|
96
|
+
| `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 |
|
|
97
|
+
| `exclude` | `[]` | Rule ids to disable |
|
|
98
|
+
| `includeUpstreamPending` | `true` | Include rules already proposed to the upstream engine but not yet merged |
|
|
99
|
+
|
|
100
|
+
To opt out of a single rule, pass its id in `exclude`. In observe-only mode, individual findings can also be suppressed with the CDK acknowledge mechanism shown in the warning text.
|
|
101
|
+
|
|
102
|
+
## Bundled rules
|
|
103
|
+
|
|
104
|
+
See [docs/rules.md](docs/rules.md) for the generated rule table. Highlights:
|
|
105
|
+
|
|
106
|
+
* **ELBv2**: `idle_timeout` / `deregistration_delay` / `slow_start` attribute ranges (stringly-typed Key/Value attributes are invisible to schema validation)
|
|
107
|
+
* **IAM**: managed (6,144 chars) and inline (role/group/user) policy document size limits
|
|
108
|
+
* **CloudFront**: `MinTTL <= DefaultTTL <= MaxTTL` ordering, ACM certificates must live in `us-east-1`
|
|
109
|
+
* **Step Functions**: `Next`/`Default`/`Choices` must reference defined states (a dangling `StartAt` is already caught by the engine's built-in `E3601`)
|
|
110
|
+
* **EC2**: security group TCP/UDP port ranges and `FromPort <= ToPort`
|
|
111
|
+
|
|
112
|
+
## For AI agents
|
|
113
|
+
|
|
114
|
+
To add cdk-preflight to a CDK app:
|
|
115
|
+
|
|
116
|
+
1. `npm i -D cdk-preflight`
|
|
117
|
+
2. `npx cdk-preflight init` — or the shorter alias `npx cdkpf init` (finds the entry point via `cdk.json` and inserts `Preflight.apply(app)`; use `--dry-run` to preview)
|
|
118
|
+
3. Run `cdk synth`. Violations fail the synth with a validation report; each finding carries a rule id, the actual value, and a suggested fix
|
|
119
|
+
4. To fix a finding, prefer correcting the resource. To opt out instead: `exclude: ['<rule-id>']` disables one rule, `enforce: false` switches to warn-only reporting
|
|
120
|
+
|
|
121
|
+
The machine-readable findings are written to `cdk.out/validation-report.json` when synthesizing with `-c @aws-cdk/core:validationReportJson=true`.
|
|
122
|
+
|
|
123
|
+
### Report missed deploy errors
|
|
124
|
+
|
|
125
|
+
cdk-preflight only knows the failure modes it has benched. When a deploy fails on a constraint the pack should have caught, that report is how new rules get added — but at that moment cdk-preflight is out of the loop (it passed the synth), so the instruction has to already sit in your agent's context. Paste this into your repository's `AGENTS.md` (or `CLAUDE.md`):
|
|
126
|
+
|
|
127
|
+
```markdown
|
|
128
|
+
## cdk-preflight: report missed deploy errors
|
|
129
|
+
|
|
130
|
+
If `cdk deploy` fails even though `cdk synth` (with cdk-preflight enabled) passed,
|
|
131
|
+
and the failure is a service-side validation rejection — CREATE_FAILED/UPDATE_FAILED
|
|
132
|
+
with a 400-class message such as "Invalid request provided: ..." — cdk-preflight is
|
|
133
|
+
missing a rule. Report it:
|
|
134
|
+
|
|
135
|
+
1. Qualify first. NOT reportable: AccessDenied / permissions, service quotas,
|
|
136
|
+
throttling, name conflicts with existing resources, stabilization timeouts.
|
|
137
|
+
2. Redact account-specific data (account IDs -> 123456789012, real ARNs/domains
|
|
138
|
+
-> placeholders).
|
|
139
|
+
3. Search existing issues: https://github.com/badmintoncryer/cdk-preflight/issues
|
|
140
|
+
4. With your user's approval, open a "Missed deploy error" issue with the verbatim
|
|
141
|
+
error message, the resource type, a minimal template snippet, and your
|
|
142
|
+
aws-cdk-lib / cdk-preflight versions.
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Scope and rule lifecycle
|
|
146
|
+
|
|
147
|
+
A constraint belongs in the pack when violating it makes a real deployment fail *and* no layer that sees the same synthesized template already blocks it. There is no further "is this worth a rule" question — if the gap is real, it gets a rule.
|
|
148
|
+
|
|
149
|
+
CDK L2 construct validation is deliberately **not** one of those layers. `CfnXxx` usage, escape hatches, `addPropertyOverride`, `cloudformation-include` and migrated templates all bypass L2, so an L2 guard covering the same mistake neither disqualifies a rule nor retires one.
|
|
150
|
+
|
|
151
|
+
That makes growth the normal state, and it has a consequence worth knowing before you upgrade: **new rules land in minor releases, so a minor upgrade can newly fail a `cdk synth` that passed yesterday.** That is intended, not a regression. If you need a frozen rule set, pin the version; to drop a single rule, `exclude: ['<rule-id>']`; to see everything without failing the build, `enforce: false`.
|
|
152
|
+
|
|
153
|
+
Rules move the other way too. Once the validation engine bundled in `aws-cdk-lib` (or CloudFormation's own pre-deploy validation) starts blocking a constraint, the rule is deleted rather than kept as a duplicate — staying on an older `aws-cdk-lib` and an older cdk-preflight keeps the old behavior.
|
|
154
|
+
|
|
155
|
+
## How it works
|
|
156
|
+
|
|
157
|
+
`Preflight.apply()` evaluates the rules with the [cloudformation-validate](https://github.com/aws-cloudformation/cloudformation-validate) Rust/WASM engine that ships inside `aws-cdk-lib` — no extra binaries, no network access at synth time. In the default enforce mode the engine is invoked through a dedicated CDK validation plugin so that violations fail synthesis; with `enforce: false` the rules are instead injected into the CDK built-in `CloudFormationValidatePlugin` and reported as warnings.
|
|
158
|
+
|
|
159
|
+
Constraints that *can* be expressed in schemas or generic engine rules also make good upstream PRs to that engine, but nothing here waits on one — the upstream release cycle is deliberately slower than this pack's. Each rule's `meta.yaml` tracks its upstream status so that retirement stays bookkeeping.
|
|
160
|
+
|
|
161
|
+
## Requirements
|
|
162
|
+
|
|
163
|
+
* `aws-cdk-lib` >= 2.267.0, released 2026-08-27 (the first release that bundles the built-in CloudFormation validator). This is a recent release — an existing CDK app may need an upgrade before cdk-preflight can run.
|
|
164
|
+
|
|
165
|
+
## Contributing
|
|
166
|
+
|
|
167
|
+
Rule authoring, the verification gates (including real-deploy reproduction), and the test layout are documented in [AGENTS.md](AGENTS.md) — written for AI coding agents and humans alike.
|
|
168
|
+
|
|
169
|
+
## License
|
|
170
|
+
|
|
171
|
+
Apache-2.0
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
cdk_preflight/__init__.py,sha256=A1HOln9rJVC3MWQ4Aa64sAtPduMs22Ut_4sckdGGgT0,20269
|
|
2
|
+
cdk_preflight/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
3
|
+
cdk_preflight/_jsii/__init__.py,sha256=fG64si-btQvcdVPsMndINI5eEl70kJW2MtMFvdh93G8,501
|
|
4
|
+
cdk_preflight/_jsii/cdk-preflight@0.0.53.jsii.tgz,sha256=iFE0Y5syDS5BVE6PKotOy1ntq1nCEAoVLMJSr-i9Jhw,779957
|
|
5
|
+
cdk_preflight-0.0.53.data/scripts/cdk-preflight,sha256=8dAw8dA39nfm2UO5shQqOyRrxirTlUbYSGPCFgySZN4,397
|
|
6
|
+
cdk_preflight-0.0.53.data/scripts/cdkpf,sha256=8-bx69OKAVRKQtDHwOlCnDSqdoLnwgxYfhGokzuYiRQ,383
|
|
7
|
+
cdk_preflight-0.0.53.dist-info/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
8
|
+
cdk_preflight-0.0.53.dist-info/METADATA,sha256=9QFTYH2r__v0Z6uFRP_5CG83N2b5GCSm4XHYo-npx9M,10903
|
|
9
|
+
cdk_preflight-0.0.53.dist-info/WHEEL,sha256=BNRMDyzLkkcmlv0J8ppDQkk2VED33SesJDynr9ED1gc,91
|
|
10
|
+
cdk_preflight-0.0.53.dist-info/top_level.txt,sha256=hUIh41e1ILkhjLPiFKniCK0AiWdNju6JIRE-5PzSpEo,14
|
|
11
|
+
cdk_preflight-0.0.53.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
cdk_preflight
|