AWS CDK Patterns

VerifiedSafe

Common AWS CDK patterns and constructs for building cloud infrastructure with TypeScript, Python, or Java. Use when designing reusable CDK stacks and L3 constructs.

Sby Skills Guide Bot
DevOpsIntermediate
7/28/2026
Claude CodeCursorWindsurfCopilotCodex
#aws-cdk#infrastructure-as-code#aws#typescript#cloud-architecture

Recommended for

Automated summary

A best-practices guide for designing reusable AWS CDK stacks and L2/L3 constructs in TypeScript, Python, or Java.

Strengths

  • Provides a complete, working serverless API pattern (API Gateway + Lambda + DynamoDB) with X-Ray tracing and grantReadWriteData.
  • States clear rules: prefer L2 constructs over L1, enforce least-privilege IAM, and split stateful from stateless resources across stacks.
  • Includes a concrete do/don't checklist (Tags.of, RemovalPolicy, cdk diff before deploy) plus troubleshooting for circular dependencies between stacks.

Limitations

  • AWS CDK only — it offers nothing for raw CloudFormation templates or Terraform.
  • All code samples are TypeScript, even though Python and Java are advertised in the description.
  • Stays at the level of general patterns; little guidance on testing, CI/CD pipelines, or migrating existing stacks.
When to use it

Reach for it when designing or reviewing a multi-stack CDK application that needs reusable constructs and production-grade defaults.

When not to use it

Skip it if you are hand-writing CloudFormation templates, working in Terraform, or just need a one-off CLI resource creation.

Security analysis

Safe
Quality score80/100

The skill provides guidance and code examples for AWS CDK infrastructure patterns without declaring or instructing any tool execution. It does not contain destructive commands, data exfiltration, obfuscation, or unsafe practices. The code is declarative infrastructure-as-code, not executed by the agent in a risky manner.

No concerns found

How this analysis is made

Examples

Reusable serverless API construct
Write a reusable CDK L3 construct in TypeScript that bundles API Gateway, a Node 20 Lambda, and a DynamoDB table with pay-per-request billing, X-Ray tracing, and least-privilege permissions.
Split stateful and stateless stacks
Refactor my single CDK stack into separate stateful (DynamoDB, S3) and stateless (Lambda, API Gateway) stacks, and explain how to avoid circular dependencies between them.
CDK code review
Review my AWS CDK app for anti-patterns: I'm using CfnTable and CfnFunction directly, hardcoded account IDs, and no removal policies. Suggest L2 replacements and production-readiness fixes.

name: cdk-patterns description: "Common AWS CDK patterns and constructs for building cloud infrastructure with TypeScript, Python, or Java. Use when designing reusable CDK stacks and L3 constructs." risk: unknown source: community date_added: "2026-02-27"

You are an expert in AWS Cloud Development Kit (CDK) specializing in reusable patterns, L2/L3 constructs, and production-grade infrastructure stacks.

Use this skill when

  • Building reusable CDK constructs or patterns
  • Designing multi-stack CDK applications
  • Implementing common infrastructure patterns (API + Lambda + DynamoDB, ECS services, static sites)
  • Reviewing CDK code for best practices and anti-patterns

Do not use this skill when

  • The user needs raw CloudFormation templates without CDK
  • The task is Terraform-specific
  • Simple one-off CLI resource creation is sufficient

Instructions

  1. Identify the infrastructure pattern needed (e.g., serverless API, container service, data pipeline).
  2. Use L2 constructs over L1 (Cfn*) constructs whenever possible for safer defaults.
  3. Apply the principle of least privilege for all IAM roles and policies.
  4. Use RemovalPolicy and Tags appropriately for production readiness.
  5. Structure stacks for reusability: separate stateful (databases, buckets) from stateless (compute, APIs).
  6. Enable monitoring by default (CloudWatch alarms, X-Ray tracing).

Examples

Example 1: Serverless API Pattern

import { Construct } from "constructs";
import * as apigateway from "aws-cdk-lib/aws-apigateway";
import * as lambda from "aws-cdk-lib/aws-lambda";
import * as dynamodb from "aws-cdk-lib/aws-dynamodb";

export class ServerlessApiPattern extends Construct {
  constructor(scope: Construct, id: string) {
    super(scope, id);

    const table = new dynamodb.Table(this, "Table", {
      partitionKey: { name: "pk", type: dynamodb.AttributeType.STRING },
      billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
      removalPolicy: cdk.RemovalPolicy.RETAIN,
    });

    const handler = new lambda.Function(this, "Handler", {
      runtime: lambda.Runtime.NODEJS_20_X,
      handler: "index.handler",
      code: lambda.Code.fromAsset("lambda"),
      environment: { TABLE_NAME: table.tableName },
      tracing: lambda.Tracing.ACTIVE,
    });

    table.grantReadWriteData(handler);

    new apigateway.LambdaRestApi(this, "Api", { handler });
  }
}

Best Practices

  • ✅ Do: Use cdk.Tags.of(this).add() for consistent tagging
  • ✅ Do: Separate stateful and stateless resources into different stacks
  • ✅ Do: Use cdk diff before every deploy
  • ❌ Don't: Use L1 (Cfn*) constructs when L2 alternatives exist
  • ❌ Don't: Hardcode account IDs or regions — use cdk.Aws.ACCOUNT_ID

Troubleshooting

Problem: Circular dependency between stacks Solution: Extract shared resources into a dedicated base stack and pass references via constructor props.

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/aws-cdk-patterns-ms47vq6i/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/aws-cdk-patterns-ms47vq6i' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/aws-cdk-patterns-ms47vq6i/download' --output '.skill-downloads/aws-cdk-patterns-ms47vq6i/SKILL.md.part' && mv '.skill-downloads/aws-cdk-patterns-ms47vq6i/SKILL.md.part' '.skill-downloads/aws-cdk-patterns-ms47vq6i/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/aws-cdk-patterns-ms47vq6i/SKILL.md' && test -s '.skill-downloads/aws-cdk-patterns-ms47vq6i/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/cdk-patterns' && cp -R '.skill-downloads/aws-cdk-patterns-ms47vq6i' '.claude/skills/cdk-patterns'

Cursor
test -f '.skill-downloads/aws-cdk-patterns-ms47vq6i/SKILL.md' && test -s '.skill-downloads/aws-cdk-patterns-ms47vq6i/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/cdk-patterns' && cp -R '.skill-downloads/aws-cdk-patterns-ms47vq6i' '.cursor/skills/cdk-patterns'

Codex
test -f '.skill-downloads/aws-cdk-patterns-ms47vq6i/SKILL.md' && test -s '.skill-downloads/aws-cdk-patterns-ms47vq6i/SKILL.md' && mkdir -p '.agents/skills' && test ! -e '.agents/skills/cdk-patterns' && cp -R '.skill-downloads/aws-cdk-patterns-ms47vq6i' '.agents/skills/cdk-patterns'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/aws-cdk-patterns-ms47vq6i'

openskills read 'aws-cdk-patterns-ms47vq6i'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/aws-cdk-patterns-ms47vq6i/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills