Aws cdk development

From NVlabs/Skill2Env · View interactive version

Aws cdk development is an AI agent skill from the GitHub repository NVlabs/Skill2Env. AWS Cloud Development Kit (CDK) expert for building cloud infrastructure with TypeScript/Python. Use when creating CDK stacks, defining CDK constructs, implementing infrastructure as code, or when the user mentions CDK, CloudFormation, IaC, cdk synth, cdk deploy, or wants to define AWS infrastructur

How to use this skill

Skill file

AWS CDK Development

This skill provides comprehensive guidance for developing AWS infrastructure using the Cloud Development Kit (CDK), with integrated MCP servers for accessing latest AWS knowledge and CDK utilities.

AWS Documentation Requirement

Always verify AWS facts using MCP tools (mcp__aws-mcp__* or mcp__*awsdocs*__*) before answering. The aws-mcp-setup dependency is auto-loaded — if MCP tools are unavailable, guide the user through that skill's setup flow.

CDK-Specific MCP Guidance

AWS Labs replaced the dedicated CDK MCP server (awslabs.cdk-mcp-server) with the broader awslabs.aws-iac-mcp-server, which covers CDK alongside CloudFormation and other AWS infrastructure-as-code workflows.

For CDK construct lookups, best-practice recommendations, and pattern guidance, install awslabs.aws-iac-mcp-server. It ships in the deploy-on-aws plugin from awslabs/agent-plugins, or can be registered directly with claude mcp add aws-iac uvx awslabs.aws-iac-mcp-server@latest.

When to reach for it:

When to Use This Skill

Use this skill when:

Core CDK Principles

Resource Naming

CRITICAL: Do NOT explicitly specify resource names when they are optional in CDK constructs.

Why: CDK-generated names enable:

Pattern: Let CDK generate unique names automatically using CloudFormation's naming mechanism.

// ❌ BAD - Explicit naming prevents reusability and parallel deployments
new lambda.Function(this, 'MyFunction', {
  functionName: 'my-lambda',  // Avoid this
  // ...
});

// ✅ GOOD - Let CDK generate unique names
new lambda.Function(this, 'MyFunction', {
  // No functionName specified - CDK generates: StackName-MyFunctionXXXXXX
  // ...
});

Security Note: For different environments (dev, staging, prod), follow AWS Security Pillar best practices by using separate AWS accounts rather than relying on resource naming within a single account. Account-level isolation provides stronger security boundaries.

Lambda Function Development

Use the appropriate Lambda construct based on runtime:

TypeScript/JavaScript: Use @aws-cdk/aws-lambda-nodejs

import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs';

new NodejsFunction(this, 'MyFunction', {
  entry: 'lambda/handler.ts',
  handler: 'handler',
  // Automatically handles bundling, dependencies, and transpilation
});

Python: Use @aws-cdk/aws-lambda-python

import { PythonFunction } from '@aws-cdk/aws-lambda-python-alpha';

new PythonFunction(this, 'MyFunction', {
  entry: 'lambda',
  index: 'handler.py',
  handler: 'handler',
  // Automatically handles dependencies and packaging
});

Benefits:

Pre-Deployment Validation

Use a multi-layer validation strategy for comprehensive CDK quality checks:

Layer 1: Real-Time IDE Feedback (Recommended)

For TypeScript/JavaScript projects:

Install cdk-nag for synthesis-time validation:

npm install --save-dev cdk-nag

Add to your CDK app:

import { Aspects } from 'aws-cdk-lib';
import { AwsSolutionsChecks } from 'cdk-nag';

const app = new App();
Aspects.of(app).add(new AwsSolutionsChecks());

Optional - VS Code users: Install CDK NAG Validator extension for faster feedback on file save.

For Python/Java/C#/Go projects: cdk-nag is available in all CDK languages and provides the same synthesis-time validation.

Layer 2: Synthesis-Time Validation (Required)
  1. Synthesis with cdk-nag: Validate stack with comprehensive rules

```bash

cdk synth # cdk-nag runs automatically via Aspects

```

  1. Suppress legitimate exceptions with documented reasons:

```typescript

import { NagSuppressions } from 'cdk-nag';

// Document WHY the exception is needed

NagSuppressions.addResourceSuppressions(resource, [

{

id: 'AwsSolutions-L1',

reason: 'Lambda@Edge requires specific runtime for CloudFront compatibility'

}

]);

```

Layer 3: Pre-Commit Safety Net
  1. Build: Ensure compilation succeeds

```bash

npm run build # or language-specific build command

```

  1. Tests: Run unit and integration tests

```bash

npm test # or pytest, mvn test, etc.

```

  1. Validation Script: Meta-level checks

```bash

./scripts/validate-stack.sh

```

The validation script now focuses on:

Workflow Guidelines

Development Workflow

  1. Design: Plan infrastructure resources and relationships
  2. Verify AWS Services: Use AWS Documentation MCP to confirm service availability and features
  1. Implement: Write CDK constructs following best practices
  1. Validate: Run pre-deployment checks (see above)
  2. Synthesize: Generate CloudFormation templates
  3. Review: Examine synthesized templates for correctness
  4. Deploy: Deploy to target environment
  5. Verify: Confirm resources are created correctly

Stack Organization

Testing Strategy

Using MCP Servers Effectively

When to Use AWS Documentation MCP

Always verify before implementing:

Example scenarios:

When to Use CDK MCP Server

Leverage for CDK-specific guidance:

Example scenarios:

MCP Usage Best Practices

  1. Verify First: Always check AWS Documentation MCP before implementing new features
  2. Regional Validation: Check service availability in target deployment regions
  3. CDK Guidance: Use CDK MCP for construct-specific recommendations
  4. Stay Current: MCP servers provide latest information beyond knowledge cutoff
  5. Combine Sources: Use both skill patterns and MCP servers for comprehensive guidance

CDK Patterns Reference

For detailed CDK patterns, anti-patterns, and architectural guidance, refer to the comprehensive reference:

File: references/cdk-patterns.md

This reference includes:

Additional Resources

GitHub Actions Integration

When GitHub Actions workflow files exist in the repository, ensure all checks defined in .github/workflows/ pass before committing. This prevents CI/CD failures and maintains code quality standards.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.