Skip to content

can i run express api on EC2 instance without load balancer? trying to lower costs

0

First i'll explain past scenario when i used EC2 instance with load balancer and then ask question better with that context.

I ran an EC2 instance for 1-2 weeks. This instance just had a running expressjs app that was an API. My live frontend sometimes called this API for getting and posting data. Barely anyone used the app while it was live. Like 2 people for a total of 2-5 minutes and me checking it off and on for a week. In the end, it cost me like $20 for those 1-2 weeks of no one using the app. Costs came from Elastic Load Balancing, VPC, EC2-Instances, Route 53, Ec2-other, and S3. I thought everything was using free tier so i was confused i got charged anything.

Now im about to do the same thing. Will be running frontend app with backend API running on EC2. My questions:

  • do i really need load balancer? i dont plan for this to be some app tons of people are using - at least no time soon
  • is it even possible to do this without load balancer...and if so, is it worth it to do without - or is it just too much of a pain without one (even if it saves money)?
  • im also curious where VPC charges came from

cost and usage breakdown

1 Answer
0

do i really need load balancer? i dont plan for this to be some app tons of people are using - at least no time soon

You don't necessarily need load balancer. Just keep in mind that you lose the scalability and high availability that a load balancer provides. (e.g., if you have any sort of failure or surge in traffic your application might be unavailable).

is it even possible to do this without load balancer...and if so, is it worth it to do without - or is it just too much of a pain without one (even if it saves money)?

Yes. You can expose your EC2 instance directly using public IP or by assigning Elastic IP to the instance without using a load balancer. it's actually simpler in terms of setting it up compared to use load balancer.

im also curious where VPC charges came from

You can have a breakdown of cost per resource in each service to get better visibility to what contributed to your cost the most. See my answer here for more details. most likely these cost are related to the hourly cost of using public IPv4 address.

AWS
EXPERT
answered a year ago
EXPERT
reviewed a year ago
  • To clarify, a load balancer won't improve availability or scalability with just one EC2 instance in any significant way. It could filter out malicious or unnecessary requests, if properly configured to do so, but in this case, the most likely value from the load balancer is that it allows terminating TLS with a certificate issued by Amazon Certificate Manager (ACM) at no additional cost. To use HTTPS without a load balancer or CloudFront, a TLS certificate would have to be obtained from a third party certificate authority and maintained either manually or with a third-party automation.

  • So far, all that makes sense, thank you. Im curious, could i use AWS Certificate Manager to get a certificate and then use that cert with CloudFront and:

    1. the API would work fine over HTTPS endpoint without load balancer
    2. no need for 3rd party cert
    3. no need for automating maintaining some 3rd party cert ?

    i dont completely understand what CloudFront's part in this is except maybe providing a domain? but maybe you all can understand where im at and help further

  • If you're using HTTPS between the CloudFront distribution and your EC2 instance serving as the origin service (=backend server called by CloudFront), the origin has to have a publicly trusted certificate for CloudFront to accept it. You could use https://letsencrypt.org/ for a free certificate, though, and I think they have just the kind of third-party client program we discussed to renew them automatically. I think CloudFront also trusts certificates from Let's Encrypt, so you could use CloudFront+ACM towards your users and Let's Encrypt between CloudFront and your instance.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.