How to make lambda return 429 on invocation limit

0

I have implemented a lambda function that synchronously handles HTTP requests through AWS loadbalancer. Since lambdas have invocation limits the lambda might be overloaded/throttled when a lot of requests (>1000) are received at the same time.

Since these requests fail because of throttling, I assumed that the loadbalancer-lambda integration would return a 429 code, allowing the client to retry the request at a better time. But this is not the case, whenever the lambda fails because of heavy load the return code is a simple 500 and not a 429. Making the client either retry at a too fast rate or simply believing the service to be broken.

This makes it very difficult to guarantee a stable service, how can I make sure that the lambda returns the more correct 429 code whenever it is throttled?

Thank you!

Philip
已提问 1 个月前118 查看次数
2 回答
0

Hi

Unfortunately, you can't directly force a Lambda function to return a 429 error upon throttling. Here's why, and potential solutions: Lambda Throttling Behavior: When a Lambda function is throttled, it usually triggers an internal error within the Lambda service, often resulting in a 5xx type error response. Lambda itself is not designed to emit a 429.

Alternative solutions/Workaround:

profile picture
专家
GK
已回答 1 个月前
  • This isn't about API Gateway, this is about ALB -> Lambda.

  • @Max I just corrrected the answer thanks for the info

0

Hi,

Is there an important reason why you use ALB instead of standard pattern API GTW + Lambda ?

If the case of this standard pattern with GTW, you will get a 429 on throttling. See https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-request-throttling.html for example

Best,

Didier

profile pictureAWS
专家
已回答 1 个月前
  • Hi,

    The loadbalancer existed before the lambda and handles requests in a certain path. I want the lambda to handle a subpath of the same path the loadbalancer handles, so to avoid having the loadbalancer handling the request that I want to go to the lambda, I put the lambda as an action for a rule in the loadbalancer.

    Best regards, Philip

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则