6

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

1
  • One is IaaS and the latter combo is PaaS + FaaS? Commented Feb 3, 2018 at 6:40

1 Answer 1

9

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your answer. The API I am building is part of a medical application which even though on its initial release may not have large number of users but soon it will be constantly invoked by different services. Given this future scenario in mind, I think EC2 might suit the need. Your thoughts??
@codeinprogress With EC2 you will have to setup auto-scaling and use a load balancer. With Lambda you wouldn't need to worry about scalability.
It's worth noting that API Gateway has a 10MB hard limit on message size. If you will ever potentially need to send relatively large payloads then your best option is to use an Application Load Balancer. However, if you are using Lambda as your back end, then ALB is still not the correct choice, as there is a 1MB hard limit on message size when Lambda is the target for the ALB. So, you can instead use the ALB to deliver very large requests to EC2. Network Load Balancer may also be an option for you to deliver to EC2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.