Skip to content

coderabbit-demo/rabbits-playground-aws-cdk

Repository files navigation

Rabbits Playground AWS CDK

This project contains the AWS infrastructure for Rabbits Playground, ported from Terraform/Terragrunt to AWS CDK.

Architecture

The infrastructure includes:

  • VPC: Multi-AZ networking with public and private subnets
  • EKS: Kubernetes cluster with managed node groups (ARM64/Graviton instances)
  • Bastion: EC2 bastion host for secure access
  • S3: Static content and user content buckets with lifecycle policies
  • CloudFront: CDN for static content delivery
  • Route53: DNS management and routing

Project Structure

├── bin/
│   └── rabbits-playground-aws-cdk.ts    # CDK app entry point
├── lib/
│   ├── constructs/                       # Reusable constructs
│   │   ├── vpc-construct.ts
│   │   ├── eks-construct.ts
│   │   ├── bastion-construct.ts
│   │   ├── s3-construct.ts
│   │   ├── cloudfront-construct.ts
│   │   └── route53-construct.ts
│   └── stacks/
│       └── infrastructure-stack.ts       # Main infrastructure stack
├── config/
│   └── environment.ts                    # Environment-specific configurations
└── cdk.json                             # CDK configuration

Environments

Two environments are supported:

  • dev: Development environment with cost-optimized settings
  • prod: Production environment with high-availability settings

Key Differences

Feature Dev Prod
VPC CIDR 10.0.0.0/16 10.1.0.0/16
NAT Gateways 1 (cost optimization) 3 (multi-AZ HA)
EKS Capacity SPOT instances ON_DEMAND instances
EKS Instance Type t4g.medium t4g.large, t4g.xlarge
EKS Nodes 2 desired (1-3) 3 desired (3-10)
EKS API Access Public Private
Log Retention 7 days 30 days
S3 Versioning Disabled Enabled
S3 Lifecycle Disabled Enabled (IA at 90d, Glacier at 180d)

Prerequisites

  • Node.js 14.x or later
  • AWS CLI configured with appropriate credentials
  • AWS CDK CLI: npm install -g aws-cdk

Setup

  1. Install dependencies:
npm install
  1. Configure AWS credentials:
export AWS_ACCOUNT_ID=your-account-id
export AWS_REGION=us-west-2
  1. Bootstrap CDK (first time only):
cdk bootstrap aws://${AWS_ACCOUNT_ID}/${AWS_REGION}

Deployment

Deploy to Dev Environment

cdk deploy -c environment=dev

Deploy to Prod Environment

cdk deploy -c environment=prod

Useful Commands

  • npm run build - Compile TypeScript to JavaScript
  • npm run watch - Watch for changes and compile
  • npm run test - Run unit tests
  • cdk diff -c environment=dev - Compare deployed stack with current state
  • cdk synth -c environment=dev - Emit the synthesized CloudFormation template
  • cdk deploy -c environment=dev - Deploy stack to AWS account/region
  • cdk destroy -c environment=dev - Remove stack from AWS account/region

Configuration

Environment-specific configurations are defined in config/environment.ts. Update these values as needed for your environments:

  • VPC CIDR ranges
  • EKS cluster settings
  • Bastion access CIDRs
  • S3 bucket names
  • Domain names
  • Route53 hosted zone settings

Connecting to Resources

EKS Cluster

After deployment, configure kubectl:

aws eks update-kubeconfig --region us-west-2 --name rabbits-playground-dev

Bastion Host

Connect via SSM Session Manager:

aws ssm start-session --target <instance-id>

Or via SSH (if key pair configured):

ssh -i your-key.pem ec2-user@bastion.dev.example.com

Outputs

After deployment, the stack outputs include:

  • VPC ID and subnet IDs
  • EKS cluster endpoint and security group
  • Bastion host IPs
  • S3 bucket names and ARNs
  • CloudFront distribution domain name
  • Route53 hosted zone details

Security Considerations

  • EKS nodes run in private subnets
  • Bastion host uses IMDSv2 and SSM for secure access
  • S3 buckets have encryption and public access blocking enabled
  • CloudFront enforces HTTPS-only access
  • Security groups restrict traffic by default
  • IAM roles follow principle of least privilege

Migration from Terraform

This CDK implementation replaces the previous Terraform/Terragrunt setup with equivalent functionality:

  • Terraform modules → CDK constructs
  • Terragrunt environments → CDK context
  • Remote state in S3 → CloudFormation stacks
  • Outputs → CDK CfnOutput

Support

For issues or questions, please refer to the AWS CDK documentation:

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published