Python Lambda Function - Timeout error

0

Hello team, I Have a lambda function (in Python code) that it's execution works fine 4/5 times, but suddenly it return this error message: "...Task timed out after <x.y> seconds" for some time (and execution) and after that it returns to work fine. I already increased the lambda's **Timeout ** and the Memory (although when the execution works the Report says that it took ~500ms and 29mb of memory) but it didn't solve the problem. I tried to comment some parts of the code to understand eventually bug, but it looks like a "random" error. The log shows something like this (my "print" statements are not logged): INIT_START Runtime Version: python:3.10.v5 Runtime Version ARN: ..... START RequestId: ... Version: $LATEST 2023-07-05T09:44:11.982Z ..... Task timed out after 5.01 seconds END RequestId: ... REPORT RequestId: .... Duration: 5007.99 ms Billed Duration: 5000 ms Memory Size: 1024 MB Max Memory Used: 29 MB INIT_START Runtime Version: python:3.10.v5 Runtime Version ARN: ..... By the way the function mount an EFS, I configured the SecurityGroup for the lambda and that for the VPC, where the EFS is located, but I think there isn't a configuration problem, because when the error doesn't come in, the function is integrated perfectly with the EFS, otherwise I think it shouldn't have worked at all.

Please let me know if I have missed anything or something I can try to fix the issue or investigate the cause better.

Thank you for your time, E.

asked 10 months ago616 views
3 Answers
0
Accepted Answer

Hi team, finally I found; there was a problem with s3 and the code config; I added this config on my code, when S3 boto3 client is created: config=botocore.config.Config(s3={'addressing_style': 'path'}).

Thanks to all.

answered 10 months ago
0

Seems as your function timed out after 5 seconds, have you increased that to lets say 30sec?

Is your lambda in the same VPC as the EFS file system?

profile picture
EXPERT
answered 10 months ago
  • Hi Antonio, thanks for your response, yes, I increased it, I also tried with 1 min, the result is the same; yes, the lambda is configured on the same VPC of the EFS, in fact as I said before, it works fine (lambda read and write from EFS) for some execution, but then start to return that error, for some time (or for some execution)

0

I don't know what sort of configuration and exception-handling you have in your code, but is it possible you're getting API request-throttling? Boto3 handles some of this for you, retrying API calls rejected due to throttling and retrying with exponential backoff up to a retry limit. See https://boto3.amazonaws.com/v1/documentation/api/latest/guide/retries.html.

In summary there are 3 modes - Default/Legacy, Standard and Adaptive (experimental). You can configure the mode and number of retries (5 by default). Retrying is exponential backoff base 2.

You can monitor retrying either in Boto3's logging (if enabled) or in the response to API calls. It's not clear from the doco but along with the documented structure returned by each call there's also ResponseMetadata with RetryAttempts in it.

EXPERT
answered 10 months ago
  • Hi thanks, for you response, I don't have any retrying exception-handling in my code, I can try to add it, but I think that if is a request-throttling problem, I should have gotten some sort of exception (I suppose), instead there aren't log, there are only the logs statement that I wrote in my first post; I have a print statement on first line of code and isn't show at all

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions