AWS Lambda Recursive Functions - Troubleshooting Throttling Errors

Troubleshooting Throttling Errors

Prev Question Next Question

Question

You just developed code in AWS Lambda that makes use of recursive functions.

After several invocations, you are beginning to see throttling errors in the metrics.

Which of the following should be done to resolve this issue?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

Answer - C.

This is also clearly mentioned in the AWS Documentation.

Avoid using recursive code in your Lambda function, wherein the function automatically calls itself until some arbitrary criteria are met.

This could lead to an unintended volume of function invocations and escalated costs.

If you accidentally do so, set the function concurrent execution limit to 0 immediately to throttle all invocations to the function while you update the code.

Option A is incorrect because placing the recursive function in a separate package still causes the throttling errors.

Option B is incorrect because using versioning for a recursive function means storing the code in other versions.

The recursive function still causes issues.

Option D is incorrect because adding an API gateway does not remove the recursive function and the issue still exists.

For more information on the best practices for AWS Lambda, please refer to the below URL-

https://docs.aws.amazon.com/lambda/latest/dg/best-practices.html

When you are using AWS Lambda to execute your code, you can run into throttling errors if the function is invoked too frequently. This can happen when you use recursive functions that are invoked multiple times, leading to a large number of concurrent requests. In this scenario, you have to take necessary steps to avoid throttling errors.

The best approach to resolve the issue is to use a combination of options B and C.

B. Use versioning for the recursive function: Versioning allows you to create and manage multiple versions of a Lambda function. With versioning, you can deploy a new version of your function without affecting the existing version, which can help you avoid conflicts or breaking changes. This allows you to manage the recursion limit in each version separately. By setting a recursion limit on the function version, you can limit the number of times the function can invoke itself before it stops. This helps to prevent the function from exceeding the maximum number of concurrent requests and triggering a throttling error.

C. Avoid using recursive code altogether: If you find that your recursive function is causing a high number of concurrent requests, you can consider avoiding recursive code altogether. You can use loops instead of recursion, which can be more efficient in some cases. Loops can allow you to perform the same operation multiple times without creating a new stack frame, as happens with recursion.

A. Place the recursive function in a separate package: Placing the recursive function in a separate package may not help in avoiding throttling errors. The issue is not with the function being in the same package as other functions, but with the function itself being invoked too frequently.

D. Use the API gateway to call the recursive code: The API Gateway is used to manage and control access to web services. It is not a solution to avoid the throttling issue. The issue arises due to the high number of requests generated by the recursive function, and using the API Gateway to call the function does not solve this problem.

Therefore, option B and C are the best approaches to resolve the throttling error in the case of recursive functions in AWS Lambda.