This CDK project creates a complete, production-ready AWS infrastructure for Ajit N K's personal website as part of AWS Builder Challenge #2. The architecture follows AWS Well-Architected Framework principles with emphasis on security, cost optimization, and operational excellence.
- π Route 53: DNS management with custom domain (ajitnk.in)
- πͺ£ Amazon S3: Private bucket with encryption, versioning, and lifecycle policies
- β‘ CloudFront: Global CDN with custom domain, SSL certificate, and security headers
- π§ AWS Lambda: Serverless contact form processing with input validation
- πͺ API Gateway: RESTful API with throttling and CORS configuration
- π§ Amazon SNS: Email notifications for contact form submissions
- π AWS Certificate Manager: SSL/TLS certificates for HTTPS
βββββββββββββββ ββββββββββββββββ βββββββββββββββ
β Route 53 βββββΆβ CloudFront βββββΆβ S3 Bucket β
β DNS β β CDN β β Website β
βββββββββββββββ ββββββββββββββββ βββββββββββββββ
β
βΌ
ββββββββββββββββ βββββββββββββββ
β API Gateway βββββΆβ Lambda β
β REST API β β Contact Formβ
ββββββββββββββββ βββββββββββββββ
β
βΌ
βββββββββββββββ
β SNS β
β Notificationsβ
βββββββββββββββ
Ensure you have the following installed and configured:
# Install AWS CDK CLI globally
npm install -g aws-cdk@2.87.0
# Configure AWS credentials (choose one method)
aws configure # Interactive configuration
# OR
export AWS_ACCESS_KEY_ID=your-access-key
export AWS_SECRET_ACCESS_KEY=your-secret-key
export AWS_DEFAULT_REGION=us-east-1
# Verify AWS configuration
aws sts get-caller-identity# Clone and navigate to project
cd aws-builder-challenge-cdk
# Install dependencies
npm install
# Verify TypeScript compilation
npm run build
# Synthesize CloudFormation templates (recommended for validation)
cdk synth# Bootstrap CDK in your AWS account (one-time setup)
cdk bootstrap
# Deploy all stacks
npm run deploy
# Or deploy with custom domain parameter
cdk deploy --parameters domainName=ajitnk.in
# Monitor deployment progress
# Deployment typically takes 15-20 minutes due to CloudFront distribution creationAfter deployment, CDK will output Route 53 name servers. Update your domain registrar (GoDaddy) with these name servers:
- Go to GoDaddy DNS Management
- Change name servers to the Route 53 name servers from CDK output
- Wait 5-15 minutes for DNS propagation
- Check email for SNS subscription confirmation
- Upload website files using the automation scripts
The stack provides these outputs for automation scripts:
WebsiteBucketName: S3 bucket name for file uploadsCloudFrontDistributionId: For cache invalidationWebsiteUrl: Final website URL (https://ajitnk.in)ApiGatewayUrl: Contact form API endpointRoute53NameServers: Name servers for GoDaddy configurationSNSTopicArn: Email notification topic
The infrastructure is optimized for AWS Free Tier:
- S3: Versioning with lifecycle rules
- CloudFront: Price Class 100 (US, Canada, Europe only)
- Lambda: 256MB memory, 30s timeout
- API Gateway: Throttling configured
- Route 53: ~$0.50/month (only paid service)
- Private S3 bucket with Origin Access Control (OAC)
- HTTPS enforcement via CloudFront
- Security headers (HSTS, CSP, X-Frame-Options)
- Input validation and sanitization in Lambda
- Rate limiting on API Gateway
- Encrypted S3 storage
npm run build # Compile TypeScript to JS
npm run watch # Watch for changes and compile
npm run test # Run unit tests
npm run deploy # Build and deploy all stacks
npm run destroy # Delete all stacks
npm run bootstrap # Bootstrap CDK (one-time setup)
npm run diff # Compare deployed stack with current state
npm run synth # Emit the synthesized CloudFormation template
# Direct CDK commands
cdk deploy # Deploy this stack to your default AWS account/region
cdk diff # Compare deployed stack with current state
cdk synth # Emit the synthesized CloudFormation template
cdk destroy # Delete the stackFor efficient development, follow this workflow:
# 1. Make changes to your CDK code
# 2. Synthesize to validate (recommended over npm run build)
cdk synth
# 3. Check differences before deployment
cdk diff
# 4. Deploy changes
npm run deployImportant: Use cdk synth instead of npm run build for validation as it:
- Automatically compiles TypeScript when needed
- Validates CDK constructs and catches deployment issues
- Generates CloudFormation templates for inspection
- Provides more informative error messages
lib/
βββ website-stack.ts # Main stack orchestration
βββ dns-stack.ts # Route 53 hosted zone
βββ s3-stack.ts # S3 bucket configuration
βββ cloudfront-stack.ts # CloudFront distribution and SSL
βββ api-stack.ts # Lambda + API Gateway + SNS
bin/
βββ app.ts # CDK app entry point
cdk.out/ # Generated CloudFormation templates
node_modules/ # Dependencies
package.json # Project configuration and scripts
tsconfig.json # TypeScript configuration
cdk.json # CDK configuration
All resources are tagged for cost tracking and organization:
- Project: AWS-Builder-Challenge-2
- Owner: Ajit-N-K
- Environment: Production
- Service: [S3, CloudFront, Lambda, etc.]
- Purpose: [Website-Storage, Website-CDN, etc.]
The stack accepts these parameters:
domainName: Custom domain name (default: ajitnk.in)
Example with custom domain:
cdk deploy --parameters domainName=yourdomain.comThe contact form backend includes:
- Input validation (name, email, message required)
- HTML sanitization to prevent XSS
- Rate limiting for security
- Email notifications via SNS
- CORS configuration for web integration
After deployment:
- Note the Route 53 name servers from CDK output
- Update your domain registrar's name servers
- DNS propagation typically takes 5-15 minutes
- Both
ajitnk.inandwww.ajitnk.inwill work
Basic monitoring is included:
- CloudWatch metrics for all services
- Lambda function logs
- API Gateway access logs
- CloudFront access logs (optional)
Deployment fails with "Domain already exists":
- Check if Route 53 hosted zone already exists
- Ensure domain name parameter matches your actual domain
CloudFront distribution takes too long:
- CloudFront distributions typically take 15-20 minutes to deploy
- This is normal AWS behavior, not a project issue
SNS email not received:
- Check spam folder
- Confirm email subscription from AWS SNS
- Verify SNS topic ARN in outputs
Website not accessible:
- Ensure DNS propagation is complete (5-15 minutes)
- Check CloudFront distribution status
- Verify S3 bucket has website files uploaded
# Check stack status
aws cloudformation describe-stacks --stack-name WebsiteStack
# View CloudFormation events
aws cloudformation describe-stack-events --stack-name WebsiteStack
# Check CDK differences
cdk diff
# Validate CloudFormation template
cdk synth > template.yaml
aws cloudformation validate-template --template-body file://template.yamlThis infrastructure demonstrates:
- β Infrastructure as Code (CDK)
- β Serverless architecture
- β Security best practices
- β Cost optimization
- β Professional custom domain
- β Global content delivery
- β Working contact form
- β HTTPS encryption
After successful deployment:
- Upload Website Content: Use the provided S3 bucket name to upload your website files
- Test Contact Form: Verify the API Gateway endpoint works correctly
- Monitor Costs: Use AWS Cost Explorer to track spending
- Set Up Alerts: Configure CloudWatch alarms for monitoring
- Backup Strategy: Consider implementing automated backups for critical data
- AWS CDK Documentation
- AWS Well-Architected Framework
- AWS Free Tier
- CloudFront Documentation
- Route 53 Documentation
This project is licensed under the MIT License - see the LICENSE file for details.
Ajit N K (@ajitnk2006)
- Website: ajitnk.in
- AWS Builder Challenge #2 Submission
Ready for AWS Builder Challenge #2 submission! π