I want to deploy a nodejs express application which also works with an rds instance. I’ve already set it up using beanstalk, but load balancing cost me half of the overall bill, which is absurd since I couldn’t configure SSL on beanstalk’s EC2 instance without the loadbal.
I’m using GitHub actions for cicd, I’m willing to use codepipeline as well. I’m even willing to containerize the entire thing.
It’s a cost efficient project, i could really use some input here.
you asked what is the cheapest. the cheapest is to put it in aws lambda, and figure out how to transform lambda events into express calls. google tells me there are tried ways to do this.
cheap yes, but with downsides:
any kind of local storage is a goner. do you want sessions? need to rework.
highly parallel. if a dozen requests hit at once, you’ll have multiple instances starting up. which is good, but your database backend might cough up blood.
cold starts. if you have a megabyte of static files, the first hit after a few minutes inactivity will take a few hundred ms to be served. the rest will be quick.
deployment requires updating a lambda function. well, it is still easier than updating ec2 installations, but something to keep in mind.
no websockets.
no background tasks.
limits on payload sizes
there are other things to consider:
the static files might be routed to an s3 bucket, via cloudfront. thus you only have to deal with the dynamic content in lambda.
do you really need an rds? in some cases, dynamodb does the job. or a combination of dynamodb, s3, s3 select and athena. if you can, consider redesigning.
I do this all the time. Appsync + Lambda or Api Gateway + Lambda. Server less products are cheaper and generally easier than VMs which can be very difficult to administer.
For anyone who needs to setup ssl with elastic beanstalk without LB,
Remove LB and serve the single instance as http 80 traffic.
In your dns, transfer the specific subdomain to cloudflare. Add a cname to the elastic beanstalk server domain in Cloudflare with proxy enabled. Cloudflare allows proxy ssl traffic. Which means connection is secure upto cloudflare. Cloudflare setup does not cost you anything.
This method is suitable only for development/staging environments because ssl termination does not go upto the server.
Without knowing what it’s used for and what’s the expected traffic level, it’s hard to make a good recommendation.
Elastic Beanstalk have single instance so you don’t have to pay for load balancer. Of course, this is for low traffic / low load workloads
You can also configure CloudFront to point to your Elastic Beanstalk environment url, which would then take care of SSL if you use ACM (this is for custom domain purpose). I haven’t tested it yet, but I don’t know why it wouldn’t work. Pointing to CloudFlare is also a free option
Now the cost should mostly be ec2 instance and rds
Now… For NodeJS API, AWS has a lot of serverless options, I would suggest looking at API Gateway + Lambda + DynamoDB. For low traffic, this is very low cost, even free in some cases
You can even do it just with Lambda with an HTTPS endpoint if you don’t mind having a random domain for the API. Then put a CloudFront and S3 static HTML for the frontend.
I guess CloudFront could also help with a custom domain for the Lambda API.
Lambda will happily use container images, just needs a little different way to handle the incoming events compared to if you’d do it with plain container services like ECS or EKS
I’ve been trying to look into it, I’m new to devops and AWS so it’s a little difficult for me to learn atm. i mean, it’s a payment gateway integration app, it doesn’t really need static files. the RDS is used for user records who are using the gateway.
I’m not sure how to implement cicd along with lambda, and how to migrate the current project to lambda in the first place. i have dockerized the current project, and am using docker-compose to launch the new build package on ebs automatically. how will this dynamic work with lambda? could you please point me towards any resources i could look into?
I’ll consider all of this, yes. it’s a pretty basic project, not in need of an LB. payment gateway integration. front end is on amplify, backend is in a docket runtime env on ebs.
I’ll look into all of this tomorrow at work, thanks a lot for the response!