DEV Community

unhurried
unhurried

Posted on

Deploying a Web API on AWS Lambda: Difference between API Gateway and Application Load Balancer

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
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
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.
  • 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

Top comments (1)

Collapse
 
rehanvdm profile image
Rehan van der Merwe

Yes bullet points! Thanks