$npx -y skills add aws-samples/sample-agent-skills-for-builders --skill aws-cdk-developmentAWS 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 defi
| 1 | # AWS CDK Development |
| 2 | |
| 3 | 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. |
| 4 | |
| 5 | ## AWS Documentation Requirement |
| 6 | |
| 7 | 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. |
| 8 | |
| 9 | ## Integrated MCP Servers |
| 10 | |
| 11 | This skill includes the CDK MCP server automatically configured with the plugin: |
| 12 | |
| 13 | ### AWS CDK MCP Server |
| 14 | **When to use**: For CDK-specific guidance and utilities |
| 15 | - Get CDK construct recommendations |
| 16 | - Retrieve CDK best practices |
| 17 | - Access CDK pattern suggestions |
| 18 | - Validate CDK configurations |
| 19 | - Get help with CDK-specific APIs |
| 20 | |
| 21 | **Important**: Leverage this server for CDK construct guidance and advanced CDK operations. |
| 22 | |
| 23 | ## When to Use This Skill |
| 24 | |
| 25 | Use this skill when: |
| 26 | - Creating new CDK stacks or constructs |
| 27 | - Refactoring existing CDK infrastructure |
| 28 | - Implementing Lambda functions within CDK |
| 29 | - Following AWS CDK best practices |
| 30 | - Validating CDK stack configurations before deployment |
| 31 | - Verifying AWS service capabilities and regional availability |
| 32 | |
| 33 | ## Core CDK Principles |
| 34 | |
| 35 | ### Resource Naming |
| 36 | |
| 37 | **CRITICAL**: Do NOT explicitly specify resource names when they are optional in CDK constructs. |
| 38 | |
| 39 | **Why**: CDK-generated names enable: |
| 40 | - **Reusable patterns**: Deploy the same construct/pattern multiple times without conflicts |
| 41 | - **Parallel deployments**: Multiple stacks can deploy simultaneously in the same region |
| 42 | - **Cleaner shared logic**: Patterns and shared code can be initialized multiple times without name collision |
| 43 | - **Stack isolation**: Each stack gets uniquely identified resources automatically |
| 44 | |
| 45 | **Pattern**: Let CDK generate unique names automatically using CloudFormation's naming mechanism. |
| 46 | |
| 47 | ```typescript |
| 48 | // ❌ BAD - Explicit naming prevents reusability and parallel deployments |
| 49 | new lambda.Function(this, 'MyFunction', { |
| 50 | functionName: 'my-lambda', // Avoid this |
| 51 | // ... |
| 52 | }); |
| 53 | |
| 54 | // ✅ GOOD - Let CDK generate unique names |
| 55 | new lambda.Function(this, 'MyFunction', { |
| 56 | // No functionName specified - CDK generates: StackName-MyFunctionXXXXXX |
| 57 | // ... |
| 58 | }); |
| 59 | ``` |
| 60 | |
| 61 | **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. |
| 62 | |
| 63 | ### Lambda Function Development |
| 64 | |
| 65 | Use the appropriate Lambda construct based on runtime: |
| 66 | |
| 67 | **TypeScript/JavaScript**: Use `@aws-cdk/aws-lambda-nodejs` |
| 68 | ```typescript |
| 69 | import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs'; |
| 70 | |
| 71 | new NodejsFunction(this, 'MyFunction', { |
| 72 | entry: 'lambda/handler.ts', |
| 73 | handler: 'handler', |
| 74 | // Automatically handles bundling, dependencies, and transpilation |
| 75 | }); |
| 76 | ``` |
| 77 | |
| 78 | **Python**: Use `@aws-cdk/aws-lambda-python` |
| 79 | ```typescript |
| 80 | import { PythonFunction } from '@aws-cdk/aws-lambda-python-alpha'; |
| 81 | |
| 82 | new PythonFunction(this, 'MyFunction', { |
| 83 | entry: 'lambda', |
| 84 | index: 'handler.py', |
| 85 | handler: 'handler', |
| 86 | // Automatically handles dependencies and packaging |
| 87 | }); |
| 88 | ``` |
| 89 | |
| 90 | **Benefits**: |
| 91 | - Automatic bundling and dependency management |
| 92 | - Transpilation handled automatically |
| 93 | - No manual packaging required |
| 94 | - Consistent deployment patterns |
| 95 | |
| 96 | ### Pre-Deployment Validation |
| 97 | |
| 98 | Use a **multi-layer validation strategy** for comprehensive CDK quality checks: |
| 99 | |
| 100 | #### Layer 1: Real-Time IDE Feedback (Recommended) |
| 101 | |
| 102 | **For TypeScript/JavaScript projects**: |
| 103 | |
| 104 | Install [cdk-nag](https://github.com/cdklabs/cdk-nag) for synthesis-time validation: |
| 105 | ```bash |
| 106 | npm install --save-dev cdk-nag |
| 107 | ``` |
| 108 | |
| 109 | Add to your CDK app: |
| 110 | ```typescript |
| 111 | import { Aspects } from 'aws-cdk-lib'; |
| 112 | import { AwsSolutionsChecks } from 'cdk-nag'; |
| 113 | |
| 114 | const app = new App(); |
| 115 | Aspects.of(app).add(new AwsSolutionsChecks()); |
| 116 | ``` |
| 117 | |
| 118 | **Optional - VS Code users**: Install [CDK NAG Validator extension](https://marketplace.visualstudio.com/items?itemName=alphacrack.cdk-nag-validator) for faster feedback on file save. |
| 119 | |
| 120 | **For Python/Java/C#/Go projects**: cdk-nag is avai |