A Lambda shows a task-timed-out error while calling an API endpoint, but the API endpoint log shows that the response was returned within a millisecond.


I build my APIs using AWS API Gateway, Lambda, and RDS. I’m calling APIs inside a Lambda, but sometimes I’m getting a task timed-out error. Why it’s happening? I checked all the things below; what else can I do?

  1. The Lambda has enough memory to handle the API calls.
  2. There is no issue with the concurrent request.
  3. The API returns a response successfully.
  4. Everything regarding RDS is OK. DB load, CPU credit, etc.
  5. As all my Lambdas are inside a VPC, there is no issue with the connectivity.
1 Answer

Difficult to say without more information. What I would suggest is to had log messages in your function to check what is taking long time.

profile pictureAWS
answered 9 months ago
  • Thanks for your comment. I have logs. Below are the steps of the execution.

    1. Inside the Lambda, the API called
    2. There is no task after the API call
    3. After 29 seconds, it shows the "Task timed out ...."
    4. The API logs show the response is returned successfully within a few milliseconds
    5. But the Lambda did not receive the response

    It's not happening always. Once or twice a day. I assumed that it could be a request throttle due to concurrent requests or the RDS resource limit being exceeded, but nothing happened.

  • The network is not a 100% reliable medium. It could be that the API responded, but the response never got to the function. What I would recommend is to put a timeout on the API call and retry in case you do not get the answer in time.

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