Application Load Balancers vs API Gateway

Viewed 19098

AWS comes with a service called Application Load Balancer and it could be a trigger to a lambda function. The way to call such a lambda function is by sending an HTTP/HTTPS request to ALB.

Now my question is how this is any different from using the API Gateway? And when should one use ALB over API Gateway (or the way around)?

2 Answers

One of the biggest reasons we use API gateway in front of our lambda functions instead of using an ALB is the native IAM (Identity and Access Management) integration that API GW has. We don't have to do any of the identity work ourselves, it's all delegated to IAM, and in addition to that, API GW has built-in request validation including validation of query string parameters and headers. In a nutshell, there are so many out of the box integrations what come with API GW, you wind up having to do a lot more work if you go the route of using an ALB.

It seems that the request/response limit is lower when using ALB, and WebSockets are not supported:

The maximum size of the request body that you can send to a Lambda function is 1 MB. For related size limits, see HTTP Header Limits.

The maximum size of the response JSON that the Lambda function can send is 1 MB.

WebSockets are not supported. Upgrade requests are rejected with an HTTP 400 code.

See: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html

Payload limit with API Gateway is discussed here: Request payload limit with AWS API Gateway

Also the article already mentioned by @matesio provides information about additional things to consider when choosing between ALB and API Gateway.

Notable tweet referenced in the mentioned article:

If you are building an API and want to leverage AuthN/Z, request validation, rate limiting, SDK generation, direct AWS service backend, use #APIGateway. If you want to add Lambda to an existing web app behind ALB you can now just add it to the needed route.

(From: Dougal Ballantyne, the Head of Product for Amazon API Gateway)

Related