Home › AWS CDK › AWS CDK (TypeScript) CLAUDE.md

AWS CDK (TypeScript) CLAUDE.md

CLAUDE.md for AWS CDK v2 apps in TypeScript: constructs, least-privilege grants, snapshot tests, and safe deploys.

Claude Code (CLAUDE.md)AWS CDK

How to use

Save this as CLAUDE.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

CLAUDE.mdDownload  
# CLAUDE.md: AWS CDK v2 (TypeScript)

## Commands
- `npm run build` · `npm test` · `npx cdk synth` · `npx cdk diff <Stack>`
- **Never run `cdk deploy` or `cdk destroy` unless asked.** Show `cdk diff` output for review instead.

## Structure
- `bin/app.ts` instantiates stacks per environment with explicit `env: { account, region }`.
- `lib/stacks/*` compose `lib/constructs/*`. Reusable pieces are L3 constructs with typed props interfaces.
- Only `aws-cdk-lib` and `constructs` imports (v2). No v1 `@aws-cdk/*` packages.

## Rules
- Permissions with grant methods (`bucket.grantRead(fn)`, `table.grantReadWriteData(fn)`) instead of hand-written IAM policies. No `*` actions or resources.
- Stateful resources (S3, DynamoDB, RDS) set `removalPolicy: RemovalPolicy.RETAIN` in production and have encryption, backups/PITR, and blocked public access.
- Don't hard-code physical names unless needed; let CDK generate them.
- Changing a construct's id replaces the resource. Avoid it for stateful resources, or call out the replacement.
- Lambdas use `NodejsFunction` with a pinned runtime (`Runtime.NODEJS_22_X`), set memory/timeout, and log retention.
- Config in `cdk.json` context or typed props, not `process.env` scattered in stacks.
- Apply `cdk-nag` (`AwsSolutionsChecks`) if the project uses it and fix findings or suppress with a reason.

## Tests
`aws-cdk-lib/assertions`: `Template.fromStack` with `hasResourceProperties` for key resources; keep snapshot tests up to date only when the diff is intended.

More: all AWS CDK rules · all Claude Code (CLAUDE.md) rules

Related rules

Kubernetes & Helm CLAUDE.md

CLAUDE.md for Kubernetes manifests and Helm 3 charts: resources, probes, security context, and safe rollouts.

Claude Code (CLAUDE.md)Kubernetes / Helm

Docker & Compose AGENTS.md

AGENTS.md for containerized projects: lean multi-stage Dockerfiles, Docker Compose for local dev, and image security.

AGENTS.mdDocker

Dockerfile Copilot path instructions

Path-specific Copilot instructions for Dockerfiles and compose files: multi-stage builds, non-root, and pinned images.

GitHub CopilotDocker

GitHub Actions workflow rules

Cursor rules for writing secure, fast GitHub Actions workflows: permissions, pinning, caching, and concurrency.

CursorGitHub Actions

GitHub Actions Copilot path instructions

Path-specific Copilot instructions for .github/workflows YAML: least privilege, pinned actions, and injection-safe steps.

GitHub CopilotGitHub Actions

Terraform Copilot instructions

Copilot instructions for Terraform 1.x / OpenTofu infrastructure: modules, state safety, variables, and plan review.

GitHub CopilotTerraform

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.