Deploying a Web API on AWS Lambda: Difference between API Gateway and Application Load Balancer
unhurried
Posted on September 7, 2019
When we deploy a web API on AWS Lambda leveraging the benefit of server less architecture, we have two options for the front-end service for Lambda: API Gateway (API GW) or Application Load Balancer (ALB). This articles studies the difference between them to help you to decide which to choose.
Features unique to API Gateway
- It is obvious, but API Gateway specific features such as Request Validation, Data Mapping, Access Control and SDK Generation cannot be used with ALB.
Protocols and Port Numbers
- API GW supports only HTTPS (TLS 1.2) on 443 port. Note that though API GW supports VPC Endpoint, you still need to use HTTPS in this case too.
- ALB supports both HTTP and HTTPS on arbitrary port numbers and TLS version also can be chosen from various options.
Request Timeout
- API GW has a severe limitation of 29 seconds.
- ALB itself doesn't have a limitation, thus the timeout of Lambda (up to 15 minutes) is applied.
Request and Response Sizes
-
API GW can handle up to 6MB payload, which is the ceiling of Lambda's payload size.
- Note that 6MB includes headers and Base64-encoded body as payloads are requests and responses of Lambda.
- The limitation of API GW's payload size is 10MB.
With ALB, the size of request and response bodies cannot be larger than 1MB. 413 error will be returned when a request body exceeds the limit, and 502 error for response body.
Request Event(Reference)
- evt.headers (Request)
- API GW sets header names and values with keeping the original upper and lower cases, whereas ALB decapitalize header names.
- evt.queryStringParameters (Request)
- When there is no query string parameter, API GW sets
null
, whereas ALB sets{}
. - API Gateway sets the URL decoded value for query string parameter key and value, whereas ALB sets them without URL decoding.
- When there is no query string parameter, API GW sets
- evt.multiValueHeaders / evt.multiValueQueryStringParameters (Request)
- API Gateway sets these parameters by default, whereas ALB requires that they are enabled in its configuration.
Response Event(Reference)
- ALB response event must include statusDescription, isBaseEncoded and headers (when "Multi Value Header" is enabled in ALB configuration).
Cost
- Up to a certain request frequency, API GW is cheaper than ALB, that has a time-based charge. However for the services that receive a large amount of requests, ALB is more reasonable. (Reference)
Other References
-
Amazon Web Services Blog
- It only mentions as follows:
there’s also a lot of overlap and commonality between the parameters used by Amazon API Gateway for triggering Lambda functions and ALB’s parameters.
- It only mentions as follows:
- API Gateway vs Application Load Balancer—Technical Details
-
API Gateway vs. ALB - 持田システム
- It covers the difference in request timeout and limitation on response size.
💖 💪 🙅 🚩
unhurried
Posted on September 7, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.