TLDR; - I moved my liftosaur.com from Cloudflare Workers to AWS Lambda + Dynamo, it wasn't easy, I built a skeleton to simplify that process for other folks who'd need to start a project in AWS - https://github.com/astashov/aws-cdk-lambda-typescript-starter.
I recently moved my Liftosaur from Cloudflare Workers to AWS Lambda + DynamoDB. There were several reasons:
- Cloudflare KV store (their database) is very limited (no secondary indexes, no backups, no table scans).
- Cloudflare workers don't have anything like layers in AWS Lambdas, you have to bundle all your server code into a bundle, and there's a limit of 1MB per bundle to run there. Mine was 900kb and growing, and that was starting to get scary :)
- Cloudflare workers don't have proper logging, monitoring, etc - I had no idea how my service behaves in production.
- Cloudflare dev server (for local development) crashes constantly. It's just annoying, I have to restart it like every 10 minutes.
It was pretty cheap though - flat $5/month for everything.
AWS seemed like a good target to move - AWS Lambdas are more featureful and flexible with their layers and built in logging and monitoring. AWS Dynamo has secondary indexes and backups every second (!), and also various monitoring and logging. And there's a whole universe, if I ever need any other service (like, sending emails, use queues, etc) - there's a service for it.
And the price for using all of that in AWS was < $5/month as well.
Migration took a while though. Learning curve is very steep, there're a lot of different services in AWS, need to figure out how to configure them properly, and in the cheapest way possible. The default local development environment is poor. AWS has a command line tool called SAM, which can run your lambdas locally, but oh boy it works poorly. It runs the lambdas in a container, and restarts the container on each request (wtf?!), so each request takes like 10 seconds, thought it should take 30ms.
It took me several weeks to migrate it fully, and I couldn't really find a good skeleton I could use as a foundation for my project. I wanted:
- Minimal CDK template for infrastructure. AWS CDK is a relatively new tool for describing all your AWS infrastructure in TypeScript code. It's very cool, because you don't have to create all those lambdas, databases, S3 buckets, etc, etc in AWS console UI, you could describe all of that in TypeScript file, and it will create all the services for you.
- CDK should configure it to be as cheap as possible for relatively small traffic, while I have tens and hundreds of customers, not hundreds of thousands, and not millions.
- Fast and reliable local development environment - a server that restarts automatically and instantly on code changes. As I said before, the default dev server is very poor.
- Should be easy to deploy my app, ideally via the same CDK.
- NodeJS + TypeScript + React + server-side rendering support (SSR)
- Multiple environments - I want to be able to test my changes in development/QA environment first, before deploying it fully to production. So, development and production should have separate S3 buckets, lambdas, databases, a separate domain, etc.
- Ideally - serve the statics (CSS and JS bundles) and HTML from the same domain, to not worry about cross-domain issues. But still serve CSS and JS from CDN, to not sacrifice app performance.
After I did all of that for Liftosaur, I then decided to build a skeleton project with all those features, maybe it could help somebody who wants to start a project in AWS. Here it is: https://github.com/astashov/aws-cdk-lambda-typescript-starter.
So, check it out!