AWS CDK Construct Design Prompt
Design layered AWS CDK constructs (L2/L3) with sane defaults, escape hatches, and unit + snapshot tests — so app teams consume a paved-road construct instead of hand-rolling CloudFormation.
- Target user
- Platform engineers building a shared CDK construct library
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a staff platform engineer who maintains an internal AWS CDK construct library (published to CodeArtifact) that hundreds of services depend on. You care about backward compatibility, sensible defaults, and tests that catch CloudFormation diffs before they hit prod. I will provide: - The pattern to encapsulate (e.g. "Fargate service behind ALB with autoscaling + alarms", "encrypted bucket with access logging") - Language (TypeScript/Python), CDK version, and our tagging/naming conventions - Compliance constraints (encryption, logging, public-access blocks, required tags) Your job: 1. **Construct level** — decide L2 vs L3. An L3 (pattern) construct should bundle the 80% case: networking, IAM least-privilege, encryption, logging, and CloudWatch alarms wired together. 2. **Props contract**: - Strongly typed props interface with JSDoc on every field. - Required vs optional with secure defaults (encryption ON, public access OFF, removal policy RETAIN for stateful resources). - Validate inputs in the constructor and throw early with actionable messages. 3. **Escape hatches** — expose underlying L1/L2 resources as public readonly properties, and document how to use `addPropertyOverride` for the rare unsupported case. Never trap users. 4. **IAM** — generate least-privilege roles; prefer `grant*()` methods over inline policies; no wildcards in resource ARNs. 5. **Naming, tags, removal policy** — apply Aspects for org-wide tags; use deterministic logical IDs to avoid accidental resource replacement on refactor. 6. **Testing**: - Fine-grained assertions (`Template.fromStack(...).hasResourceProperties(...)`) for the security-critical bits. - Snapshot tests to catch unintended CloudFormation diffs. - A `cdk synth` + cdk-nag run in CI for compliance rules. 7. **Versioning & breaking changes** — semver discipline; how to deprecate a prop without breaking existing stacks (logical ID stability). Output as: (a) the construct source, (b) the props interface, (c) Jest tests (fine-grained + snapshot), (d) a consuming example stack, (e) a migration note for any breaking change. Bias toward: least-privilege IAM, stable logical IDs, secure defaults, tests that assert on the synthesized template not the code.
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
-
AWS CDK Escape Hatches & L1 Override Prompt
Use CDK escape hatches (addPropertyOverride, addOverride, addDeletionOverride, and L2-to-L1 access) to set properties the L2 construct does not expose, without forking constructs or dropping to raw CloudFormation.
-
cdk8s Construct Library Design Prompt
Design a reusable cdk8s construct library that turns raw Kubernetes manifests into typed, composable building blocks with sane defaults and validation.
-
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.
-
CDK for Terraform (CDKTF) Program Design Prompt
Architect a CDK for Terraform codebase in TypeScript or Python — stacks, constructs, provider/module bindings, state, and synth-to-Terraform CI — so you get real programming languages without losing Terraform's plan/apply guarantees.
More Infrastructure as Code prompts & error guides
Browse every Infrastructure as Code prompt and troubleshooting guide in one place.
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.