Skip to content
🎉 Launch sale:50% off everything over $22 — automatically applied at checkout· ends Aug 2Shop the sale →
DevOps AI ToolKit
Newsletter
All prompts
AI for Infrastructure as Code Difficulty: Advanced ClaudeChatGPT

AWS CDK Aspects Compliance Enforcement Prompt

Write AWS CDK Aspects that visit the construct tree to enforce tagging, encryption, and security rules across all stacks at synth time.

Target user
Platform engineers enforcing guardrails in CDK pipelines
Difficulty
Advanced
Tools
Claude, ChatGPT

The prompt

You are a senior infrastructure-as-code engineer who enforces org-wide guardrails in AWS CDK using Aspects that fail the synth before anything reaches CloudFormation.

I will provide:
- The CDK language (TypeScript or Python) and app structure
- The policies to enforce (required tags, encryption at rest, no public S3, allowed instance types)
- Whether violations should warn or hard-fail

Your job:

1. **Implement the Aspect** — provide a class implementing `IAspect` with a `visit(node)` that inspects each construct in the tree.
2. **Match nodes precisely** — use the L1 Cfn resource type or `instanceof` on L2 constructs to target the right resources, and skip irrelevant nodes.
3. **Annotate, don't throw** — attach findings with `Annotations.of(node).addError()` / `addWarning()` so all violations surface in one synth, not just the first.
4. **Apply at the right scope** — show `Aspects.of(app).add(new MyAspect())` and explain app-level vs stack-level application and ordering.
5. **Handle mutation vs validation** — if the Aspect also fixes resources (e.g. adds tags), explain Aspect invocation order and the risk of mutating after synth-dependent logic.
6. **Test** — provide an assertion test that synthesizes a stack with a violation and asserts the error annotation.

Output as: the Aspect class, the wiring in `app.ts`/`app.py`, and a test proving a violation fails synth.

Note that addError blocks deploy while addWarning does not — choose per policy and state which you used.

Run this prompt with AI

Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.

Related prompts

More Infrastructure as Code prompts & error guides

Browse every Infrastructure as Code prompt and troubleshooting guide in one place.

Free download · 368-page PDF

Reading prompts? Get all 500 in one free PDF

500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.

  • 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
  • Instant PDF download — yours free, forever
  • Plus one practical AI-workflow email a week (no spam)

Single opt-in · unsubscribe anytime · no spam.