Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js RESTful API server on AWS EC2 vs AWS API Gateway

I have a node.js RESTful API application. There is no web interface (at least as of now) and it is just used as an API endpoint which is called by other services.

I want to host it on Amazon's AWS cloud. I am confused between two options

  1. Use normal EC2 hosting and just provide the hosting url as the API endpoint

OR

  1. Use Amazon's API Gateway and run my code on AWS Lambda

Or can I just run my code on EC2 and use API Gateway?

I am confused on how EC2 and API Gateway are different when it comes to a node.js RESTful api application

like image 584
codeinprogress Avatar asked Feb 03 '18 06:02

codeinprogress


1 Answers

Think of API Gateway as an API management service. It doesn't host your application code, it does provide a centralized interface for all your APIs and allows you to configure things like access restrictions, response caching, rate limiting, and version management for your APIs.

When you use API Gateway you still have to host your API's back-end application code somewhere like Lambda or EC2. You should compare Lambda and EC2 to determine which best suits your needs. EC2 provides a virtual Linux or Windows server that you can install anything on, but you pay for every second that the server is running. With EC2 you also have to think about scaling your application across multiple servers and load balancing the requests. AWS Lambda hosts your functions and executes them on demand, scales out the number of function containers automatically, and you only pay for the number of executions (and it includes a large number of free executions every month). Lambda is going to cost much less unless you have a very large number of API requests every month.

like image 99
Mark B Avatar answered Sep 18 '22 17:09

Mark B