I’m a developer and for my side hustle I started creating a SPA project based on some of the best practices. I chose Fargate, so I could easily scale up in the future. The most basic RDS, added CDN and also had to use NAT Gateway.
I have two EC2 instances, one for frontend and one for backend and also connected them to Codepipeline. Plus one LightSail to host the blog of site
The total cost for all these with no traffic currently is $120 per month.
Could I have chosen a cheaper approach? I currently see two options:
1- Replacing NAT Gateway with https://github.com/AndrewGuenther/fck-nat
2- I could use Lambdas for hosting the site instead of EC2, but I haven’t seen anyone doing that without encountering more issues.
If you are using EC2, you are not using Fargate. In Fargate you pay only for the running containers, something with 0.25CPU and 0.5RAM cost around 10 USD.
For the database you can run Aurora Serverless, with 0.5 ACU it should be pretty cheap as well. You can build all that with ECS and AWS Copilot which uses an interesting approach to avoid NAT Gateways, it just deploy your tasks with public IPs by default
The other route is the serverless one, you can try Amplify, host the SPA with Amplify Hosting, use Lambda for the APIs and maybe DynamoDB for storage. That’s really cheap for a project or low traffic site, including the free tiers you can probably run it for free.
I have a backend that process stuff and the react that’s dockerized. Beside changing django to work with dynamodb is such a pain and would require more work.
For a small site with cost being a factor, I would have done this differently.
RDS is expensive. I avoid it like the plague for small personal projects. I choose dynamo where possible or occasionally use EC2 instead for hosting an instance.
Why are you hosting a front end on its own EC2? Can it be hosted in s3+cloudfront instead?
You said you chose fargate, but also ec2 for the backend? What is each doing in this case?
Lambda + API gateway is how I do low-cost personal stuff
Most cost efficient design I know: cloudfront, S3, API Gateway, dynamodb, Lambda.
You will only pay something if your site has a lot of traffic, most of these services have a huge free tier.
I’m developing my application right now, and I have a full deployed system with this stack, I only pay 50 cents a month because of Route 53 for DNS management.
What’s the downside of hosting react on S3 and Cloudfront?
I chose to not use dynamodb, because backend was with django and it’s too much effort to get it work with dynamo.
I wasn’t sure about hosting backend on Lambda, as I read there were some issue with using this approach.
React build result is just a file, there is no downside as I see. S3 is the cheapest way to store files on AWS, cloudfront will give you low latency if you want, but in this case we use it just to route traffic to the S3 bucket.
It’s all on fargate, fargate underneath uses EC2. just one EC2 for jumpbox. I didn’t consider s3+cloudfront in the beginning cause I didn’t know about it.
4- it is personal project for now, but I’m quitting my job to work on it fully so it might scale up.
About dynamo, you will have to write your own queries, also, designing a NoSQL solution is somewhat different from SQL, which will have a learning curve. You could use aurora serverless, it would reduce your db costs significantly and it’s SQL.
this is the way! if there is no lambda (or equivalent) then i’d rather just host my shit on prem with a few cheap compact PCs - which is fun at first but this means forever hardware maintenance.
What do you mean your frontend is on EC2? Your SPA code is client side code / files. And can be served from a CDN, unless you’re doing server side rendering.
I would stay off EC2 or fargate, especially for a side project. There is no need to go on fargate in-case you need to scale.
It sounds like you already have some type of docker containerisation already so maybe take a look at dumping your existing setup and move to AppRunner https://aws.amazon.com/apprunner/.
RDS does have a free tier for new accounts so maybe looking at using a T2/T3 micro (from memory).
If you can’t move to a serverless model (lambda etc) for whatever reason, you should seriously consider using SQLite for your database, that way you can completely remove RDS costs.
Why do you need a NAT gateway? They cost an absolute fortune. Avoid them unless you have a very specific reason.
A serious suggestion would be to look at using another provider as you dont sound very experienced with AWS and infrastructure, as AWS can quickly become extremely costly for people who are new to it. There are plenty of stories like this.
Fly.io is a service you could look at using, their pricing is completely clear on what you would pay, and it doesnt stop you from using cloudfront/s3 for static content and storage.
SPA to S3 fronted by cloudfront. Backend to fargate and it is optional to deploy in public vs private which means the NAT can technically be removed unless you have specific reasons for its use. I have both styles of deployments (public vs private) and the NAT is going to a large cost
Do you have any code samples you can share showing API Gateway + Lambda? I have a need to get that built pretty soon, but all of the googling I’ve done just shows vendor products to make that integration happen.
This is the appropriate architecture. This will allow you to scale your costs with the popularity of your project and if it DOES become super popular, you can migrate off the dynamic cost solutions onto fixed EC2/Fargate solutions.