Skip to content

TopCoderJP/AWS-CDK-Automation-Typescript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AWS-CDK-Automation-Typescript

πŸ—οΈ VPC CDK Project

AWS TypeScript MySQL License

A comprehensive AWS infrastructure project built with AWS CDK (Cloud Development Kit) in TypeScript, implementing a three-tier architecture with VPC, EC2, and RDS components following AWS best practices.

πŸ“‹ Table of Contents

🎯 Project Overview

This project demonstrates the implementation of a scalable three-tier web architecture on AWS using Infrastructure as Code (IaC) principles. The architecture includes:

  • Presentation Tier: Public subnets for load balancers and web servers
  • Application Tier: Private subnets for application servers (EC2 instances)
  • Data Tier: Isolated database subnets for RDS MySQL instances

✨ Key Features

  • 🌐 Multi-AZ VPC with proper subnet segmentation
  • πŸ–₯️ EC2 instances in private subnets for security
  • πŸ—„οΈ MySQL RDS database in isolated subnets
  • πŸ”’ Security best practices implemented throughout
  • πŸ“Š Performance monitoring with CloudWatch integration
  • 🏷️ Comprehensive tagging for resource management
  • πŸ’Ύ Automated backups and disaster recovery planning

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        AWS VPC                             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                 β”‚
β”‚  β”‚  Availability   β”‚  β”‚  Availability   β”‚                 β”‚
β”‚  β”‚    Zone A       β”‚  β”‚    Zone B       β”‚                 β”‚
β”‚  β”‚                 β”‚  β”‚                 β”‚                 β”‚
β”‚  β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚  β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Public Tier     β”‚
β”‚  β”‚ β”‚   Public    β”‚ β”‚  β”‚ β”‚   Public    β”‚ β”‚ (Load Balancer) β”‚
β”‚  β”‚ β”‚   Subnet    β”‚ β”‚  β”‚ β”‚   Subnet    β”‚ β”‚                 β”‚
β”‚  β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚  β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚                 β”‚
β”‚  β”‚                 β”‚  β”‚                 β”‚                 β”‚
β”‚  β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚  β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Private Tier    β”‚
β”‚  β”‚ β”‚   Private   β”‚ β”‚  β”‚ β”‚   Private   β”‚ β”‚ (EC2 App        β”‚
β”‚  β”‚ β”‚   Subnet    β”‚ β”‚  β”‚ β”‚   Subnet    β”‚ β”‚  Servers)       β”‚
β”‚  β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚  β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚                 β”‚
β”‚  β”‚                 β”‚  β”‚                 β”‚                 β”‚
β”‚  β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚  β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Database Tier   β”‚
β”‚  β”‚ β”‚  Database   β”‚ β”‚  β”‚ β”‚  Database   β”‚ β”‚ (RDS MySQL)     β”‚
β”‚  β”‚ β”‚   Subnet    β”‚ β”‚  β”‚ β”‚   Subnet    β”‚ β”‚                 β”‚
β”‚  β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚  β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚                 β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

🌐 Network Configuration

Component CIDR Block Purpose Internet Access
VPC 10.0.0.0/16 Main network container N/A
Public Subnets 10.0.1.0/24, 10.0.2.0/24 Load balancers, NAT gateways βœ… Direct
Private Subnets 10.0.3.0/24, 10.0.4.0/24 Application servers πŸ”’ Via NAT
Database Subnets 10.0.5.0/24, 10.0.6.0/24 RDS instances ❌ Isolated

πŸ”§ Components

πŸ“¦ Stack 1: VpcCdkProjectStack

Purpose: Creates the foundational network infrastructure

Resources Created:

  • βœ… VPC with DNS resolution enabled
  • βœ… Internet Gateway for public internet access
  • βœ… Public subnets across 2 Availability Zones
  • βœ… Private isolated subnets for applications
  • βœ… Database subnets for RDS placement
  • βœ… Route tables and security configurations

Key Features:

  • Multi-AZ deployment for high availability
  • Proper subnet segregation following AWS best practices
  • CIDR planning for future scalability

πŸ–₯️ Stack 2: EC2Stack

Purpose: Deploys application servers in private subnets

Resources Created:

  • βœ… EC2 instances in private subnets
  • βœ… Security groups with restricted access
  • βœ… IAM roles and policies
  • βœ… Auto-scaling capabilities (if configured)

Security Configuration:

  • No direct internet access (private subnet placement)
  • Controlled communication via security groups
  • IAM role-based permissions following least privilege principle

πŸ—„οΈ Stack 3: RDSStack

Purpose: Provides managed MySQL database service

Database Configuration

Setting Value Description
Engine MySQL 8.0.35 Latest stable MySQL version
Instance Type t3.micro Cost-effective for development
Storage 20GB initial, 30GB max Auto-scaling enabled
Multi-AZ Disabled For cost optimization (enable for production)
Encryption Enabled Data encryption at rest
Backup Retention 7 days Automated daily backups

Advanced Features

  • πŸ” AWS Secrets Manager integration for credential management
  • πŸ“Š Performance Insights enabled (7-day retention)
  • πŸ” Enhanced Monitoring with 60-second intervals
  • βš™οΈ Custom Parameter Group for MySQL optimization
  • 🏷️ Comprehensive tagging for resource management

Database Optimizations

-- InnoDB Buffer Pool optimized for t3.micro
innodb_buffer_pool_size = 75% of instance memory (~750MB)

πŸ’° Cost Estimation

Monthly Cost Breakdown (US East-1)

Service Configuration Estimated Cost
VPC Standard VPC with subnets Free
EC2 t3.micro instances ~$8.50/month
RDS t3.micro MySQL ~$15.00/month
Storage 20GB GP2 ~$2.00/month
Data Transfer Minimal usage ~$1.00/month
Total ~$26.50/month

πŸ’‘ Free Tier Eligible: New AWS accounts can run this architecture within the free tier limits for 12 months!

πŸš€ Getting Started

Prerequisites

  • βœ… AWS Account with appropriate permissions
  • βœ… AWS CLI configured with credentials
  • βœ… Node.js (16.x or later)
  • βœ… AWS CDK installed globally
  • βœ… Git for version control

πŸ› οΈ Installation

  1. Clone the repository
git clone <git@github.com:TopCoderJP/AWS-CDK-Automation-Typescript.git>
cd vpc-cdk-project
  1. Install dependencies
npm install
  1. Configure AWS credentials
aws configure
# Enter your Access Key ID, Secret Access Key, Region, and Output format
  1. Bootstrap CDK (first time only)
cdk bootstrap

πŸ“ Project Structure

vpc-cdk-project/
β”œβ”€β”€ bin/
β”‚   └── vpc-cdk-project.ts          # Main app entry point
β”œβ”€β”€ lib/
β”‚   β”œβ”€β”€ vpc-cdk-project-stack.ts    # VPC infrastructure
β”‚   β”œβ”€β”€ ec2-stack.ts                # EC2 instances
β”‚   └── rds-stack.ts                # RDS database
β”œβ”€β”€ package.json                    # Dependencies
β”œβ”€β”€ tsconfig.json                   # TypeScript config
└── README.md                       # This file

πŸ“¦ Deployment

Step-by-Step Deployment

  1. Validate the code
npm run build
  1. Preview changes
cdk diff
  1. Deploy all stacks
cdk deploy --all

Or deploy individually:

cdk deploy VpcCdkProjectStack  # Deploy VPC first
cdk deploy MyEC2Stack          # Deploy EC2 instances
cdk deploy MyRDSStack          # Deploy RDS database

πŸ“‹ Deployment Output

After successful deployment, you'll receive:

  • 🌐 VPC ID: For reference in other projects
  • πŸ”— RDS Endpoint: Database connection string
  • πŸ”‘ Secret ARN: Database credentials location
  • πŸ†” Database Identifier: RDS instance identifier

πŸ” Security Features

Network Security

  • πŸ›‘οΈ Private Subnets: Application servers isolated from internet
  • πŸ”’ Database Isolation: RDS in dedicated isolated subnets
  • πŸšͺ Security Groups: Controlled traffic flow between tiers
  • πŸ” NACLs: Additional network-level security (if configured)

Data Protection

  • πŸ” Encryption at Rest: All RDS storage encrypted
  • πŸ”‘ Secrets Management: Database credentials in AWS Secrets Manager
  • πŸ”„ Automated Rotation: Credential rotation capabilities
  • πŸ“‹ IAM Policies: Least privilege access controls

Compliance Features

  • 🏷️ Resource Tagging: For governance and cost tracking
  • πŸ“Š CloudTrail Integration: API call logging (if enabled)
  • πŸ” VPC Flow Logs: Network traffic monitoring (if enabled)

πŸ“Š Monitoring & Management

CloudWatch Integration

  • πŸ“ˆ Performance Insights: Database performance monitoring
  • ⚠️ CloudWatch Alarms: Automated alerting (configurable)
  • πŸ“Š Custom Metrics: Application-specific monitoring
  • πŸ“ Log Aggregation: Centralized logging

Backup & Recovery

  • πŸ’Ύ Automated Backups: Daily RDS snapshots
  • πŸ”„ Point-in-time Recovery: 7-day retention window
  • πŸ“¦ Manual Snapshots: On-demand backup capability
  • 🌍 Cross-region Backup: (Configurable for production)

🧹 Cleanup

Remove All Resources

# Destroy all stacks (be careful!)
cdk destroy --all

Individual Stack Removal

cdk destroy MyRDSStack         # Remove database first
cdk destroy MyEC2Stack         # Remove EC2 instances
cdk destroy VpcCdkProjectStack # Remove VPC last

⚠️ Warning: This will permanently delete all resources and data. Ensure you have backups if needed!

πŸ“š Learning Resources

AWS Documentation

Architecture Patterns

CDK Resources


🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Built with ❀️ by Topcoder using AWS CDK and TypeScript

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors