The Question
I've been running this site on AWS (Amplify, Lambda, DynamoDB, Bedrock) with Cloudflare handling DNS and CDN. It costs about $1/month and works great. But lately, I've been wondering: what if I moved everything to Cloudflare?
This isn't about fixing problems—the current setup is solid. It's about exploring alternatives, understanding trade-offs, and seeing if there's a simpler, faster, or cheaper way to run the same site.
Current Architecture Recap
Before diving into migration, here's what I'm running today:
Frontend: - AWS Amplify (hosting + CI/CD) - CloudFront (CDN) - S3 (static files)
Backend: - API Gateway (REST endpoints) - Lambda (serverless functions) - DynamoDB (comments storage) - AWS Bedrock (AI chat agent) - SES (email notifications)
Edge: - Cloudflare (DNS, security, domain redirect)
Cost: ~$1/month (mostly Bedrock API calls)
What Cloudflare Offers
Cloudflare has built a comprehensive platform that could replace most of my AWS stack:
Cloudflare Pages (vs Amplify + CloudFront + S3)
What it is: Static site hosting with built-in CI/CD and global CDN.
Key features: - Unlimited bandwidth (no caps!) - Automatic deployments from GitHub - Preview deployments for PRs - Built-in analytics - Edge caching at 300+ locations - Free SSL certificates
Cost: FREE (unlimited)
Cloudflare Workers (vs Lambda + API Gateway)
What it is: Serverless functions that run at the edge, not in a single region.
Key features: - Runs at 300+ edge locations (closer to users) - No cold starts (instant execution) - V8 isolates (faster than containers) - 100,000 requests/day free tier - Sub-millisecond startup time
Cost: FREE (100k requests/day) or $5/month (10M requests)
Cloudflare D1 (vs DynamoDB)
What it is: SQLite database distributed globally at the edge.
Key features: - SQL database (easier than DynamoDB's NoSQL) - Automatic replication - Low latency reads from edge - Built-in backups
Cost: FREE tier available
The AI Problem
Here's the catch: Cloudflare doesn't have an equivalent to AWS Bedrock.
Options: 1. Workers AI: Limited models, not as powerful as Claude 2. Keep Lambda + Bedrock: Hybrid approach 3. External API: Call OpenAI/Anthropic directly from Workers
For my AI chat agent, I'd likely keep using AWS Bedrock since it's the best option for Claude integration.
Migration Scenarios
Let me explore three different approaches:
Scenario 1: Full Migration (Except AI)
Move to Cloudflare: - Frontend → Pages - Comments API → Workers + D1 - AWS Status API → Workers - Email notifications → Workers
Keep on AWS: - AI chat agent (Lambda + Bedrock)
Architecture:
`
User → Cloudflare Pages (static site)
→ Cloudflare Workers (APIs)
→ D1 (comments database)
→ AWS Lambda (AI agent only)
`
Pros: - Simpler architecture (fewer services) - No cold starts on Workers - Unlimited bandwidth - Potentially faster (edge computing) - Lower cost ($0 for most features)
Cons: - Need to rewrite Lambda functions as Workers - Learn new platform (Workers, D1) - Still need AWS for AI - Migration effort required
Scenario 2: Hybrid (Frontend Only)
Move to Cloudflare: - Frontend → Pages
Keep on AWS: - All backend APIs - AI agent - Database - Email
Architecture:
`
User → Cloudflare Pages (static site)
→ AWS API Gateway (all APIs)
→ Lambda + DynamoDB + Bedrock
`
Pros: - Minimal migration effort - Get unlimited bandwidth - Keep proven backend - Easy to test and rollback
Cons: - Still managing two platforms - Backend still has cold starts - Not fully utilizing Cloudflare
Scenario 3: Stay on AWS
Keep everything as is
Pros: - No migration needed - Everything in one place - Mature, proven services - Already optimized
Cons: - Bandwidth limits (15GB/month free) - Cold starts on Lambda - Slightly more complex than pure Cloudflare
Performance Comparison
Let me compare the key metrics:
Cold Starts
AWS Lambda: - First request: 100-500ms - Subsequent requests: <10ms (if warm) - Warm duration: 5-15 minutes
Cloudflare Workers: - First request: <1ms - All requests: <1ms - No concept of "cold" or "warm"
Winner: Cloudflare Workers (no cold starts)
Global Distribution
AWS CloudFront: - 400+ edge locations - Regional Lambda (single region) - Good global performance
Cloudflare: - 300+ edge locations - Workers run at every location - Excellent global performance
Winner: Tie (both excellent)
Bandwidth
AWS Amplify: - 15GB/month free - $0.15/GB after that
Cloudflare Pages: - Unlimited bandwidth - No overage charges
Winner: Cloudflare (unlimited)
Database Latency
DynamoDB: - Single region (eu-west-2) - 10-50ms latency from Europe - 100-200ms from other continents
Cloudflare D1: - Reads from nearest edge - <10ms latency globally - Writes go to primary region
Winner: Cloudflare D1 (for reads)
Cost Analysis
Let's break down the costs:
Current (AWS + Cloudflare)
AWS Amplify: $0 (within free tier)
Lambda: $0 (within free tier)
API Gateway: $0 (within free tier)
DynamoDB: $0 (within free tier)
Bedrock: ~$1/month
SES: $0 (low volume)
Cloudflare: $0 (free plan)
---
Total: ~$1/month
Full Cloudflare (Except AI)
Cloudflare Pages: $0
Workers: $0 (100k requests/day)
D1: $0 (within free tier)
AWS Lambda (AI): ~$1/month (Bedrock)
---
Total: ~$1/month
Hybrid (Pages + AWS Backend)
Cloudflare Pages: $0
AWS Backend: ~$1/month
---
Total: ~$1/month
Verdict: Cost is roughly the same across all scenarios. The real benefits are performance and simplicity, not cost savings.
Code Migration Effort
Frontend (Easy)
Moving to Cloudflare Pages is straightforward:
1. Connect GitHub repo 2. Configure build settings 3. Add environment variables 4. Deploy
Time: 30 minutes Complexity: Low
Backend APIs (Medium)
Rewriting Lambda functions as Workers requires some changes:
Lambda (Node.js):
`javascript
export const handler = async (event) => {
const body = JSON.parse(event.body);
// Process request
return {
statusCode: 200,
body: JSON.stringify({ result })
};
};
`
Workers (JavaScript):
`javascript
export default {
async fetch(request, env) {
const body = await request.json();
// Process request
return new Response(JSON.stringify({ result }), {
headers: { 'Content-Type': 'application/json' }
});
}
};
`
Differences: - Different event structure - Different response format - Workers use Web APIs (fetch, Request, Response) - Need to adapt to Workers runtime
Time: 2-4 hours per function Complexity: Medium
Database (Medium-High)
Migrating from DynamoDB to D1:
DynamoDB (NoSQL):
`javascript
await dynamodb.putItem({
TableName: 'comments',
Item: { id, postSlug, author, content, timestamp }
});
`
D1 (SQL):
`javascript
await env.DB.prepare(
'INSERT INTO comments (id, post_slug, author, content, timestamp) VALUES (?, ?, ?, ?, ?)'
).bind(id, postSlug, author, content, timestamp).run();
`
Challenges: - Schema design (NoSQL → SQL) - Data migration - Query rewriting - Testing
Time: 4-8 hours Complexity: Medium-High
Real-World Considerations
What I'd Gain
1. No Cold Starts - Workers respond instantly - Better user experience - No "first request is slow" problem
2. Unlimited Bandwidth - No worrying about traffic spikes - No overage charges - Good for viral content
3. Simpler Architecture - Fewer services to manage - One platform for most features - Easier mental model
4. Edge Computing - Code runs closer to users - Lower latency globally - Better performance
What I'd Lose
1. AWS Ecosystem - Mature services - Extensive documentation - Large community
2. Bedrock Integration - Best Claude AI integration - Would need hybrid approach
3. DynamoDB Features - Proven at scale - Advanced querying - Streams and triggers
4. Familiarity - I know AWS well - Would need to learn Workers/D1
My Decision
After analyzing everything, here's what I'd do:
Phase 1: Move Frontend to Cloudflare Pages
Why: - Easy migration (30 minutes) - Immediate benefits (unlimited bandwidth) - Low risk (easy to rollback) - No code changes needed
When: Now (worth trying)
Phase 2: Keep Backend on AWS
Why: - Current setup works well - Bedrock integration is valuable - Migration effort not justified - Cost is already minimal
When: Maybe later, if needs change
Phase 3: Experiment with Workers
Why: - Learn the platform - Test performance - Build new features with Workers - Gradual migration if beneficial
When: For new features
The Verdict
Should I migrate?
Frontend: Yes, move to Cloudflare Pages - Easy migration - Clear benefits - No downsides
Backend: No, stay on AWS (for now) - Current setup works well - Migration effort not justified - Bedrock is valuable
Hybrid approach is the winner: Get Cloudflare's benefits for the frontend while keeping AWS's strengths for the backend.
Lessons Learned
1. Don't migrate for the sake of migrating - Current setup costs $1/month and works great - Migration should solve real problems
2. Hybrid architectures are okay - Use the best tool for each job - Don't force everything onto one platform
3. Edge computing is powerful - Workers' no-cold-start model is compelling - Worth considering for new projects
4. Cost isn't everything - At $1/month, cost optimization isn't the goal - Performance and simplicity matter more
5. Platform lock-in is real - AWS Bedrock keeps me on AWS - But that's okay—it's the best option
What Would You Do?
If you're running a similar site, here's my advice:
Migrate to Cloudflare if: - You're starting fresh - You don't need AWS-specific services - You want the simplest possible setup - You value edge computing
Stay on AWS if: - Current setup works well - You use AWS-specific services (Bedrock, etc.) - You're comfortable with AWS - Migration effort isn't justified
Go hybrid if: - You want best of both worlds - You're willing to manage two platforms - You can benefit from both ecosystems
Conclusion
Could I move this site to Cloudflare? Yes, mostly.
Should I? Partially.
The frontend migration to Cloudflare Pages makes sense—it's easy, beneficial, and low-risk. The backend migration is harder to justify since AWS Lambda + Bedrock work well and the cost is already minimal.
Sometimes the best architecture isn't the newest or trendiest—it's the one that solves your problems simply and reliably. For now, that's a hybrid approach: Cloudflare for the edge, AWS for the backend.
But I'll keep watching Cloudflare's platform. If they add better AI capabilities or if my needs change, a full migration might make sense. For now, hybrid is the sweet spot.
---
Update: I'm planning to migrate the frontend to Cloudflare Pages as an experiment. I'll write a follow-up post about the experience, performance improvements, and any gotchas I encounter. Stay tuned!
💬 Comments (0)
Loading comments...