EveryoneCook is a social network platform for sharing cooking recipes, built entirely on AWS Cloud. The project uses a serverless architecture, leveraging AWS managed services to ensure scalability, security, and cost optimization.
The project is designed with a 5-Stack Architecture featuring clear layers:
┌─────────────────────────────────────────────────────────────┐
│ EveryoneCook Platform │
├─────────────────────────────────────────────────────────────┤
│ Layer 1: DNS & Certificate (Foundation) │
│ ├─ DNS Stack: Route 53 Hosted Zone │
│ └─ Certificate Stack: ACM Certificates (us-east-1) │
├─────────────────────────────────────────────────────────────┤
│ Layer 2: Data & Storage (Core Infrastructure) │
│ └─ Core Stack: DynamoDB, S3, CloudFront, KMS │
├─────────────────────────────────────────────────────────────┤
│ Layer 3: Authentication & Security │
│ └─ Auth Stack: Cognito, Lambda Triggers, SES │
├─────────────────────────────────────────────────────────────┤
│ Layer 4: Application & Business Logic │
│ └─ Backend Stack: API Gateway, Lambda, SQS, WAF │
├─────────────────────────────────────────────────────────────┤
│ Layer 5: Monitoring & Observability │
│ └─ Observability Stack: CloudWatch, Alarms, Dashboards │
└─────────────────────────────────────────────────────────────┘
everyonecook/
├── infrastructure/ # AWS CDK Infrastructure
│ ├── bin/
│ │ └── app.ts # CDK app entry point - creates all stacks
│ ├── lib/
│ │ ├── base-stack.ts # Base class for all stacks
│ │ ├── stacks/ # Stack definitions
│ │ │ ├── dns-stack.ts # Route 53 Hosted Zone
│ │ │ ├── certificate-stack.ts # ACM Certificates
│ │ │ ├── core-stack.ts # DynamoDB, S3, CloudFront
│ │ │ ├── auth-stack.ts # Cognito, Lambda triggers
│ │ │ ├── backend-stack.ts # API Gateway, Lambda, SQS
│ │ │ └── observability-stack.ts # CloudWatch, Alarms
│ │ └── constructs/ # Reusable CDK constructs
│ │ └── shared-layer.ts # Lambda Layer with dependencies
│ ├── config/
│ │ └── environment.ts # Environment configuration (dev/staging/prod)
│ ├── cdk.json # CDK configuration
│ ├── package.json # Node.js dependencies
│ └── tsconfig.json # TypeScript configuration
├── services/ # Lambda function source code
│ ├── api-router/ # API request routing
│ ├── auth-user/ # Authentication endpoints
│ ├── social/ # Social features (posts, comments)
│ ├── recipe-ai/ # Recipe & AI endpoints
│ ├── admin/ # Admin management
│ └── upload/ # File upload handler
├── shared/ # Shared code & utilities
│ ├── utils/ # Common utilities
│ ├── models/ # Data models
│ └── middleware/ # Lambda middleware
├── frontend/ # Next.js frontend (deployed separately)
│ └── ...
└── layers/ # Lambda layers
└── shared-dependencies/ # Common npm packages
Purpose: Create the foundation for DNS management
Main resources:
everyonecook.cloudDeployment order: This stack must be deployed first
Estimated cost: ~$0.50/month
Note: After deploying this stack, update the nameservers at Hostinger to point to Route 53.
Purpose: Create SSL/TLS certificates for CloudFront and API Gateway
Main resources:
cdn.everyonecook.cloud*.everyonecook.cloudSpecial region: MUST deploy to us-east-1 (CloudFront requirement)
Dependencies: DNS Stack (requires Hosted Zone for DNS validation)
Estimated cost: Free (ACM certificates are free)
Important note: CloudFront only accepts certificates from the us-east-1 region.
Purpose: Create the data layer and storage infrastructure
Main resources:
USER#{username}, SK: PROFILE|RECIPE#{id}|POST#{id}|COMMENT#{id}cdn.everyonecook.cloudDependencies: Certificate Stack (requires certificate for CloudFront)
Estimated cost: ~$8-15/month
Cost optimization:
- S3 Intelligent-Tiering automatically moves objects to cheaper storage
- CloudFront WAF removed (Shield Standard provides DDoS protection)
- CloudWatch Logs auto-delete after retention period
Purpose: Authentication and user management
Main resources:
Dependencies: Core Stack (Lambda triggers need access to DynamoDB)
Estimated cost: ~$0-2/month (Cognito free tier: 50,000 MAU)
Security:
- Advanced Security Mode not enabled to optimize cost (would cost an extra ~$5/month)
- Device tracking enabled but NO MFA to improve user experience
- All Lambda triggers have CloudWatch logging
Purpose: Application layer and business logic
Main resources:
api.everyonecook.cloud*.everyonecook.cloud)Shared Lambda Layer:
Dependencies: Auth Stack (requires Cognito User Pool)
Estimated cost: ~$10-25/month
Cost optimization:
- CloudFront WAF removed (Shield Standard provides DDoS protection)
- WAF only enabled for API Gateway (main attack surface)
- Lambda Layer reduces deployment size by 90%
- CloudWatch Logs auto-delete after 7 days
Purpose: Monitoring, logging, and alerting
Main resources:
EveryoneCook-{env}-AlarmsDependencies: All other stacks (monitors the entire infrastructure)
Estimated cost: ~$3-8/month
Best practice:
- Deploy this stack last for complete visibility
- Composite alarm helps reduce alarm fatigue
- 7-day log retention balances debugging needs and cost
- Cost alarms prevent unexpected bills
DNS Stack (Route 53)
↓
Certificate Stack (ACM in us-east-1)
↓
Core Stack (DynamoDB, S3, CloudFront, KMS)
↓
Auth Stack (Cognito, Lambda Triggers)
↓
Backend Stack (API Gateway, Lambda, SQS, WAF)
↓
Observability Stack (CloudWatch, Alarms)
Dependency explanation:
Development Environment:
| Service | Cost/month | Notes |
|---|---|---|
| Route 53 Hosted Zone | $0.50 | 1 hosted zone + DNS queries |
| ACM Certificates | $0 | Free for public certificates |
| DynamoDB (Pay-per-request) | $3-5 | Depends on usage, free tier available |
| S3 (Intelligent-Tiering) | $1-3 | 2 buckets, auto-tiering saves cost |
| CloudFront | $2-5 | CDN distribution + data transfer |
| Lambda | $0-3 | 7 functions + 1 worker, free tier 1M requests |
| Lambda Layer | $0 | No additional charge |
| API Gateway | $0-3 | REST API, free tier 1M requests |
| Cognito (Free tier) | $0 | Up to 50,000 MAU |
| SQS | $0-1 | 4 queues + 4 DLQs, free tier 1M requests |
| WAF (API Gateway only) | $5-8 | Web ACL + rules + requests processed |
| CloudWatch Logs | $1-2 | 7-day retention, all services |
| CloudWatch Dashboards | $0-1 | 4 dashboards, first 3 free |
| CloudWatch Alarms | $0.50-1 | 15+ alarms, $0.10/alarm |
| SNS | $0 | Email notifications, low volume |
| KMS | $2 | 2 customer-managed keys @ $1 each |
| IAM | $0 | Roles & policies are free |
| TOTAL | $15-35/month | Development with low traffic |
Note:
- This is an estimate for the development environment with low traffic
- Production environment with high traffic will have significantly higher costs
- Free tier: Cognito (50K MAU), Lambda (1M requests), API Gateway (1M requests), SQS (1M requests)
- Cost optimizations applied:
- CloudFront WAF removed (-$9/month)
- S3 Intelligent-Tiering (auto cost reduction)
- CloudWatch Logs 7-day retention
- Lambda Layer reduces deployment costs
authStack.addDependency(coreStack); backendStack.addDependency(authStack); observabilityStack.addDependency(backendStack);
1. Navigate to infrastructure directory
cd D:\Project_AWS\everyonecook\infrastructure
2. Install dependencies
npm install
TODO: Take a screenshot of the terminal with the output of
npm install
1. Review environment configuration
Open the file config/environment.ts to review the configuration:
code config\environment.ts
This file contains configuration for environments (dev, staging, prod):
// Example Dev environment configuration
dev: {
environment: 'dev',
account: '123456789012', // Update with your AWS Account ID
region: 'ap-southeast-1', // Singapore region
domains: {
frontend: 'dev.everyonecook.cloud',
api: 'api-dev.everyonecook.cloud',
cdn: 'cdn-dev.everyonecook.cloud',
},
cognito: {
passwordPolicy: {
minLength: 8, // Dev: 8 chars, Prod: 12 chars
}
}
}
2. Verify AWS Account ID
# Check current AWS Account ID
aws sts get-caller-identity
Output will show:
{
"UserId": "AIDAXXXXXXXXXXXXXXXXX",
"Account": "123456789012",
"Arn": "arn:aws:iam::123456789012:user/your-username"
}
3. Update account ID in config (if needed)
If the account ID does not match, update it in config/environment.ts:
dev: {
account: 'YOUR_ACTUAL_ACCOUNT_ID', // Update here
// ... other configs
}
1. Review main CDK app file
code bin\app.ts
The file bin/app.ts is the entry point of the CDK application. Main content:
#!/usr/bin/env node
import * as cdk from 'aws-cdk-lib';
import { getConfig } from '../config/environment';
const app = new cdk.App();
// Get environment from context (default: 'dev')
const environment = app.node.tryGetContext('environment') || 'dev';
const config = getConfig(environment);
console.log(`🚀 Deploying Everyone Cook infrastructure for environment: ${environment}`);
// Create stacks in dependency order
const dnsStack = new DnsStack(app, `EveryoneCook-${environment}-DNS`, {...});
const certificateStack = new CertificateStack(app, `EveryoneCook-${environment}-Certificate`, {...});
const coreStack = new CoreStack(app, `EveryoneCook-${environment}-Core`, {...});
const authStack = new AuthStack(app, `EveryoneCook-${environment}-Auth`, {...});
const backendStack = new BackendStack(app, `EveryoneCook-${environment}-Backend`, {...});
const observabilityStack = new ObservabilityStack(app, `EveryoneCook-${environment}-Observability`, {...});
// Add dependencies
certificateStack.addDependency(dnsStack);
coreStack.addDependency(certificateStack);
authStack.addDependency(coreStack);
backendStack.addDependency(authStack);
observabilityStack.addDependency(backendStack);
// Add tags to all stacks
cdk.Tags.of(app).add('Project', 'EveryoneCook');
cdk.Tags.of(app).add('Environment', config.environment);
cdk.Tags.of(app).add('ManagedBy', 'CDK');
2. Understand stack dependencies
Stacks are created in order and have explicit dependencies:
1. Compile TypeScript
# Navigate to infrastructure directory
cd D:\Project_AWS\everyonecook\infrastructure
# Compile TypeScript
npm run build
Successful output:
> everyonecook-infrastructure@1.0.0 build
> tsc
# No errors - compilation successful
2. List all CDK stacks
# List all stacks for dev environment
npx cdk list --context environment=dev
Output:
EveryoneCook-dev-DNS
EveryoneCook-dev-Certificate
EveryoneCook-dev-Core
EveryoneCook-dev-Auth
EveryoneCook-dev-Backend
EveryoneCook-dev-Observability
3. Synthesize CloudFormation templates
# Generate CloudFormation templates
npx cdk synth --context environment=dev
Output:
Successfully synthesized to D:\Project_AWS\everyonecook\infrastructure\cdk.out
Supply a stack id (EveryoneCook-dev-DNS, EveryoneCook-dev-Certificate, ...) to display its template.
The cdk.out/ folder is created with CloudFormation templates:
cdk.out/
├── EveryoneCook-dev-DNS.template.json
├── EveryoneCook-dev-Certificate.template.json
├── EveryoneCook-dev-Core.template.json
├── EveryoneCook-dev-Auth.template.json
├── EveryoneCook-dev-Backend.template.json
└── EveryoneCook-dev-Observability.template.json
If you want to see details of resources in each stack:
1. DNS Stack Resources
# View DNS stack template
Get-Content cdk.out\EveryoneCook-dev-DNS.template.json | ConvertFrom-Json | Select-Object -ExpandProperty Resources
Resources:
2. Certificate Stack Resources
# View Certificate stack template
Get-Content cdk.out\EveryoneCook-dev-Certificate.template.json | ConvertFrom-Json | Select-Object -ExpandProperty Resources
Resources:
cdn.everyonecook.cloud)*.everyonecook.cloud)3. Core Stack Resources
Resources (30+ resources):
4. Auth Stack Resources
Resources (20+ resources):
5. Backend Stack Resources
Resources (50+ resources):
6. Observability Stack Resources
Resources (15+ resources):
To learn more about the configuration and resources of each stack, see the following sections:
Before deploying, check the following items:
Environment Configuration
config/environment.tsDependencies
npm install)Validation
npm run build)Preparation for Deployment
After completing configuration and validation, continue to:
5.05 Deploy Infrastructure - Deploy all stacks to AWS
In the next step, you will: