The Complete Production SOP: How to Deploy and Run AWS CDK v2 L3 Construct Development & CloudFormation in Autonomous AI Agents
Deterministic SOP to synthesize CloudFormation and author L3 constructs with AWS CDK v2 in Claude Code, Codex, Cursor, and Windsurf. Includes fixes & triggers.
Technical Overview & Architectural Context
Autonomous coding agents frequently stumble when writing Infrastructure as Code (IaC) with AWS CDK v2. Left unconstrained, LLMs mix CDK v1 imports (`@aws-cdk/core`) with CDK v2 (`aws-cdk-lib`), misconfigure construct scopes by passing `this` incorrectly across nested inheritance trees, or generate non-deterministic logical IDs that cause resource replacement during deployment. Furthermore, models often default to mutating mutable properties on base L1/L2 constructs instead of encapsulating multi-resource patterns inside composed Level 3 (L3) construct abstractions. The aws-cdk-construct-library skill forces autonomous agents into strict architectural boundaries. It codifies the contract for L3 construct design: accepting explicit construct `id` and typed `Props` interfaces extending `Construct`, strictly enforcing proper `RemovalPolicy` configurations (avoiding accidental orphaned production state), and obligating the agent to validate CloudFormation logical IDs via `cdk synth` and `cdk diff` prior to proposing code completions.
Prerequisites & Environment Requirements
Verified Search Intents & Long-Tail Queries Solved
This operational tutorial is engineered to provide deterministic solutions for these developer search queries:
Step-by-Step Execution Playbook
Local Environment Setup & SKILL.md Mounting
Mount the skill manifest into your agent runtime workspace or global skills repository.
Autonomous runtimes like Claude Code, Cursor, Windsurf, and Codex index skills by scanning local markdown metadata directories. Installing this manifest ensures that whenever CDK synthesis, L3 construct creation, or diff tasks are detected, the agent loads deterministic procedural boundaries and verification rules.
mkdir -p .cursor/rules ~/.agents/skills/aws-cdk-construct-library && curl -fsSL https://askills.dev/api/skills/aws-cdk-construct-library/raw -o ~/.agents/skills/aws-cdk-construct-library/SKILL.md---
name: "aws-cdk-construct-library"
description: "Synthesize deterministic AWS CloudFormation templates using object-oriented AWS CDK v2."
metadata:
author: "AWS"
version: "1.0.0"
runtime_compatibility:
- "codex"
- "claude-code"
- "cursor"
- "windsurf"
triggers:
- "create aws cdk l3 construct"
- "run cdk diff"
- "synthesize cloudformation cdk"
permissions:
fs_read: true
fs_write: "workspace"
shell_exec: false
net_access: false
---In Cursor, symlink `~/.agents/skills/aws-cdk-construct-library/SKILL.md` to `.cursor/rules/aws-cdk.mdc` to reduce global context tokens and activate rules only on *.ts CDK files.
Do not grant `shell_exec: true` unless executing `cdk synth` in an isolated ephemeral container, as arbitrary IaC execution can invoke untrusted synthesis plugins.
TypeScript Project Scaffolding & Construct Hierarchy
Initialize CDK project structure and establish strict types for L3 construct properties.
The agent must create typed contracts using `constructs.Construct` and `aws-cdk-lib`. Every custom L3 construct must accept `scope: Construct`, `id: string`, and a custom props interface extending standard construct options. This step establishes baseline TypeScript dependencies and tsconfig flags.
npx cdk init app --language=typescript && npm install -D ts-node typescript @types/nodeimport { Construct } from 'constructs';
import { RemovalPolicy, Duration } from 'aws-cdk-lib';
import * as s3 from 'aws-cdk-lib/aws-s3';
import * as kms from 'aws-cdk-lib/aws-kms';
export interface SecureBucketProps {
readonly retentionPeriod?: Duration;
readonly autoDeleteObjects?: boolean;
}
export class SecureBucket extends Construct {
public readonly bucket: s3.Bucket;
public readonly key: kms.Key;
constructor(scope: Construct, id: string, props: SecureBucketProps = {}) {
super(scope, id);
this.key = new kms.Key(this, 'BucketKey', {
enableKeyRotation: true,
removalPolicy: RemovalPolicy.RETAIN,
});
this.bucket = new s3.Bucket(this, 'Resource', {
encryption: s3.BucketEncryption.KMS,
encryptionKey: this.key,
enforceSSL: true,
blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL,
versioned: true,
removalPolicy: props.autoDeleteObjects ? RemovalPolicy.DESTROY : RemovalPolicy.RETAIN,
autoDeleteObjects: props.autoDeleteObjects ?? false,
});
}
}Always expose instantiated underlying L2 constructs as `public readonly` members (e.g., `this.bucket`) so consuming stacks can attach event notifications or IAM grants without construct rewrites.
Avoid mixing `@aws-cdk/core` (CDK v1) dependencies in `package.json`. Doing so produces 'Construct is not an instance of Construct' runtime exceptions during synthesis.
Intent Matching & Trigger Invocation
Prompt the agent using explicit frontmatter triggers to generate L3 construct stacks deterministically.
Provide structured instructions matching the trigger patterns defined in the skill metadata (`create aws cdk l3 construct`, `synthesize cloudformation cdk`). This forces the runtime to bypass conversational prose and engage the defined execution SOP directly.
Always specify stack boundaries (e.g., Stateless vs Stateful) in the prompt to allow the agent to manage CDK `CfnOutput` exports and cross-stack references correctly.
Verification, Linting & Output Quality Gate
Run CDK template synthesis and snapshot assertions before final approval.
The skill mandates running `cdk synth` and validating logical IDs via fine-grained assertions (`aws-cdk-lib/assertions`). The agent verifies that template JSON conforms to CloudFormation schemas and that logical ID drift has not occurred.
npx cdk synth --quiet && npm testimport { App, Stack } from 'aws-cdk-lib';
import { Template, Match } from 'aws-cdk-lib/assertions';
import { SecureBucket } from '../lib/constructs/secure-bucket';
test('SecureBucket enforces KMS encryption and blocks public access', () => {
const app = new App();
const stack = new Stack(app, 'TestStack');
new SecureBucket(stack, 'MySecureBucket');
const template = Template.fromStack(stack);
template.hasResourceProperties('AWS::S3::Bucket', {
BucketEncryption: Match.objectLike({
ServerSideEncryptionConfiguration: Match.arrayWith([
Match.objectLike({
ServerSideEncryptionByDefault: {
SSEAlgorithm: 'aws:kms',
},
}),
]),
}),
PublicAccessBlockConfiguration: {
BlockPublicAcls: true,
BlockPublicPolicy: true,
IgnorePublicAcls: true,
RestrictPublicBuckets: true,
},
});
});Run `npx cdk diff` against committed templates in CI to catch unintentional updates to stateful AWS resources like DynamoDB tables or RDS instances.
Real-World Scenario: Implement a Secure S3 Data Ingestion Pipeline L3 Construct
“create aws cdk l3 construct named DataIngestionPipeline that encapsulates an S3 bucket with KMS CMK encryption, an SQS dead-letter queue, and an SNS notification topic. Then synthesize cloudformation cdk and verify assertion tests.”
Runtime Troubleshooting & Failure Modes
Root Cause: The agent attempted to interpolate a CDK token representing an array/list (such as security group IDs or subnet IDs) directly inside a string template literal rather than passing the token object or using `Fn.join`.
// Incorrect: `Subnet IDs: ${vpc.privateSubnets}`
// Correct fix:
const subnetIds = vpc.privateSubnets.map(subnet => subnet.subnetId);
// Or pass tokens directly to property bindings without template string coercionRoot Cause: Agent hallucinated AWS CDK v1 or transitional v2 sub-module paths. In CDK v2, core primitives (`Stack`, `App`, `RemovalPolicy`) reside directly in `aws-cdk-lib`, not `aws-cdk-lib/core` or `@aws-cdk/core`.
import { Stack, App, RemovalPolicy, Duration } from 'aws-cdk-lib'; // Replace import ... from 'aws-cdk-lib/core'Frequently Asked Questions (AWS CDK v2 L3 Construct Development & CloudFormation SOP)
Q:Can I use AWS CDK v2 L3 Construct Development & CloudFormation across Codex, Claude Code, and Cursor simultaneously?
Yes. The SKILL.md specification is runtime-agnostic. Claude Code reads it via registered CLI skills, Codex via system prompt inclusions or workspace rule configs, and Cursor/Windsurf via `.cursor/rules` or workspace prompt contexts.
Q:How does AWS CDK v2 L3 Construct Development & CloudFormation prevent context window overflow during long agent sessions?
The skill enforces concise verification steps: instead of dumping massive raw JSON CloudFormation templates into agent context, it directs the agent to evaluate template outputs with targeted assertions and summary diff outputs (`cdk diff`).
Q:Does this skill require escalated root or container permissions?
No. The skill is rated 98/100 on security because it operates with `shell_exec: false` and `net_access: false` by default, limiting agent activity to local workspace file read/write operations and running verified CDK synth checks.
Ready to equip your autonomous agent with AWS CDK v2 L3 Construct Development & CloudFormation?
Copy the complete audited SKILL.md specification or download the 1-click zip bundle directly from our verified registry.