Mehran
Mehran

Reputation: 16931

Application Load Balancers vs API Gateway

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)?

Upvotes: 49

Views: 24034

Answers (3)

Srinivas A
Srinivas A

Reputation: 161

API gateways usually are richer in functionality than Load balancers. In addition to load balancing, API gateways often capable to do the following:

  • Content based based routing (some calls to v1 and some calls to v2 and so on, based on certain criteria)
  • IAM related functionality (eg: access validation )
  • Security (eg: SSL offloading, DDOS attack prevention, security credentials translation - eg: translating particular type of token to another, etc)
  • Payload translation (eg: XML to Json, etc)

Additionally, API gateways may be available in appliance form - and appliances are usually of low-latency, far more secure, etc.

I am not aware of specific features of AWS API gateway, but the above ones are general features of any API gateway. Nevertheless, when you have an option to use either LB or API gateway to offer a service on internet, API gateway is usually a better option, unless there are specific reasons to choose otherwise.

Upvotes: 2

TommyN
TommyN

Reputation: 2381

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)

Upvotes: 6

Chris D'Englere
Chris D'Englere

Reputation: 436

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.

Upvotes: 17

Related Questions