Readit News logoReadit News
Posted by u/fazkan a year ago
Ask HN: Help with NextJS deployment architecture on AWS
I use pm2, with nginx in front, on a lightsail instance (ubuntu base-image) and manually run commands (clone, migrate, and pm2 restart) every time we merge to a prod branch, with the idea that eventually those commands will run as part of github actions.

The postgres is also on the same instance.

Curious if anyone has any comments on this.

Also a side question if anyone has used coolify for production apps? How was the experience?

I don't want to spend more time than is required maintaining the infra for the webapp.

Can't go with vercel or a hosted PAAS, because we have AWS credits, and don't want to spend unnecessarily.

thanks in advance

qbxk · a year ago
my 2c is package it as a Dockerfile and push it to ECR and set up an ECS fargate stack to run it. It's a little work to understand what this entails, but it will pay off, is cheap to run, and you can use it for everything.

Don't host your own db, use a t3.micro from RDS for postgres (NOT aurora). If you don't want to use RDS use an EC2 instead. Definitely don't containerize the db.

You'll also need an ALB to put in front of your ECS cluster, but you can use the same ALB for as many clusters or apps as you want

This will probably cost you $20-30/mo before bandwidth charges and will carry a lot of traffic, but if you need more you just increment how many nodes you're running, no sweat

Probably learn how to do this using the console, but you do this all with terraform and you can just rubber stamp your application infra like magic

fazkan · a year ago
this seems to be too much complexity. have you ran this setup in production? curious about the maintenance overhead required?
qbxk · a year ago
yes I run dozens of apps in a professional capacity this way. Once it's set up, there's no further maintenance, scaling is a piece of cake and can be done with a aws-sdk cli command

You will probably want a deploy script that runs the docker build command and pushes to ECR and then reboots the ECS containers. Rerun this script periodically to update your base image and libraries.

flybayer · a year ago
Hi, you might like https://www.flightcontrol.dev which fully automates production infra in your AWS. So you get to use your AWS credits, and you can even pay Flightcontrol with your credits, so it'll be 100% free.

Flightcontrol is very popular for Next.js deployments on AWS

*I'm cofounder of Flightcontrol

fazkan · a year ago
flightcontrol looks cool, looking at the docs.

Although, your comment about it being popular, is a bit salesy. I would have checked it out nonetheless.

Deleted Comment

solardev · a year ago
Can you just deploy to AWS Amplify? It's a higher level of abstraction. https://docs.aws.amazon.com/amplify/latest/userguide/deploy-...
fazkan · a year ago
Yeah, don't particularly like amplify, not enough control. Also, we use nextjs as as socket server, which does not play well with out of the box solutions.
solardev · a year ago
I see. Sounds like you got your work cut out for you. Good luck!
detuks · a year ago
https://docs.sst.dev/start/nextjs I use this for few projects
8b16380d · a year ago
CloudFront distribution backed with Appsync or API Gateway?
fazkan · a year ago
haven't tried this, or rather didn't know about this, can you share some relevant resources. And your experience with them.