Agent skill
aws-cdk
AWS Cloud Development Kit infrastructure as code patterns and best practices for serverless, containers, and cloud-native applications
Install this agent skill to your Project
npx add-skill https://github.com/ljchg12-hue/dotfiles/tree/main/skills/aws-cdk
SKILL.md
AWS CDK Skill
Infrastructure as Code (IaC) using AWS Cloud Development Kit with TypeScript/Python for building scalable cloud applications.
When to Use This Skill
Activate this skill when the user:
- Requests AWS infrastructure setup
- Needs serverless application architecture
- Wants to define cloud resources as code
- Mentions "AWS CDK", "infrastructure as code", "CloudFormation", "serverless"
- Requires best practices for AWS resource management
- Asks about container orchestration (ECS, EKS)
- Needs API Gateway, Lambda, DynamoDB patterns
Core Capabilities
1. Common CDK Patterns
- Serverless API: API Gateway + Lambda + DynamoDB
- Static Website: S3 + CloudFront + Route53
- Container Service: ECS Fargate + ALB + RDS
- Event-Driven: EventBridge + Lambda + SQS/SNS
- Data Pipeline: S3 + Lambda + Glue + Athena
- CI/CD Pipeline: CodePipeline + CodeBuild + CodeDeploy
2. CDK Constructs
- L1 (CloudFormation): Direct CFN resources
- L2 (Curated): AWS construct library
- L3 (Patterns): High-level patterns
- Custom Constructs: Reusable components
3. Best Practices
- Multi-environment deployment (dev, staging, prod)
- Tagging and cost allocation
- Security best practices (IAM, VPC, encryption)
- Monitoring and logging (CloudWatch)
- Resource cleanup and lifecycle management
Example Patterns
Serverless API Stack
import * as cdk from 'aws-cdk-lib';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as apigateway from 'aws-cdk-lib/aws-apigateway';
import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';
export class ServerlessApiStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// DynamoDB Table
const table = new dynamodb.Table(this, 'ItemsTable', {
partitionKey: { name: 'id', type: dynamodb.AttributeType.STRING },
billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
removalPolicy: cdk.RemovalPolicy.DESTROY,
});
// Lambda Function
const handler = new lambda.Function(this, 'ItemsHandler', {
runtime: lambda.Runtime.NODEJS_18_X,
code: lambda.Code.fromAsset('lambda'),
handler: 'index.handler',
environment: {
TABLE_NAME: table.tableName,
},
});
table.grantReadWriteData(handler);
// API Gateway
const api = new apigateway.RestApi(this, 'ItemsApi', {
restApiName: 'Items Service',
description: 'This service manages items.',
});
const items = api.root.addResource('items');
items.addMethod('GET', new apigateway.LambdaIntegration(handler));
items.addMethod('POST', new apigateway.LambdaIntegration(handler));
const item = items.addResource('{id}');
item.addMethod('GET', new apigateway.LambdaIntegration(handler));
item.addMethod('PUT', new apigateway.LambdaIntegration(handler));
item.addMethod('DELETE', new apigateway.LambdaIntegration(handler));
}
}
Static Website with CloudFront
import * as s3 from 'aws-cdk-lib/aws-s3';
import * as cloudfront from 'aws-cdk-lib/aws-cloudfront';
import * as s3deploy from 'aws-cdk-lib/aws-s3-deployment';
export class StaticWebsiteStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// S3 Bucket
const siteBucket = new s3.Bucket(this, 'SiteBucket', {
websiteIndexDocument: 'index.html',
websiteErrorDocument: 'error.html',
publicReadAccess: true,
removalPolicy: cdk.RemovalPolicy.DESTROY,
autoDeleteObjects: true,
});
// CloudFront Distribution
const distribution = new cloudfront.CloudFrontWebDistribution(this, 'SiteDistribution', {
originConfigs: [{
s3OriginSource: {
s3BucketSource: siteBucket,
},
behaviors: [{ isDefaultBehavior: true }],
}],
});
// Deploy site contents
new s3deploy.BucketDeployment(this, 'DeployWebsite', {
sources: [s3deploy.Source.asset('./website')],
destinationBucket: siteBucket,
distribution,
distributionPaths: ['/*'],
});
new cdk.CfnOutput(this, 'DistributionDomainName', {
value: distribution.distributionDomainName,
});
}
}
Best Practices
Do's
- ✅ Use typed constructs (TypeScript recommended)
- ✅ Separate stacks by lifecycle and team ownership
- ✅ Tag all resources for cost tracking
- ✅ Use environment variables for configuration
- ✅ Implement proper IAM least privilege
- ✅ Enable CloudWatch logs and metrics
- ✅ Use CDK context for environment-specific values
- ✅ Version lock your CDK dependencies
Don'ts
- ❌ Don't hardcode sensitive values (use Secrets Manager)
- ❌ Don't create circular dependencies between stacks
- ❌ Don't forget to set removal policies
- ❌ Don't ignore CDK security warnings
- ❌ Don't deploy to production without testing
Resources
- AWS CDK Docs: https://docs.aws.amazon.com/cdk/
- CDK Patterns: https://cdkpatterns.com/
- AWS Construct Library: https://docs.aws.amazon.com/cdk/api/v2/
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
random-selection
Randomly select items from lists using various algorithms for fair and unbiased selection
threat-hunting
Proactive threat detection using Sigma rules, IOCs, and behavioral analytics
auth-implementation-patterns
Master authentication and authorization patterns including JWT, OAuth2, session management, and RBAC to build secure, scalable access control systems. Use when implementing auth systems, securing APIs, or debugging security issues.
debugging-strategies
Master systematic debugging techniques, profiling tools, and root cause analysis to efficiently track down bugs across any codebase or technology stack. Use when investigating bugs, performance issues, or unexpected behavior.
sql-optimization-patterns
Master SQL query optimization, indexing strategies, and EXPLAIN analysis to dramatically improve database performance and eliminate slow queries. Use when debugging slow queries, designing database schemas, or optimizing application performance.
monorepo-management
Master monorepo management with Turborepo, Nx, and pnpm workspaces to build efficient, scalable multi-package repositories with optimized builds and dependency management. Use when setting up monorepos, optimizing builds, or managing shared dependencies.
Didn't find tool you were looking for?