Skip to content

Unknown timeout using Lambda Function along with API Gateway to await a response from Openai for longer than 1 minute

0

I have requested an account-level timeout limit for API Gateway to extend to 2 minutes and have enforced the 2-minute timeout limit on it. I have also ensured that the Lambda Function does not time out until 10 minutes later. The following is some proof: Enter image description here Enter image description here

I have also enabled logging on the API Gateway level and everything works fine and there's no errors being logged: Enter image description here

No issues are spotted on the Lambda Function either: Enter image description here

In short, no errors can be logged or observed while a response is indeed returned from Openai to the Lambda Function and the API Gateawy, where responses can be gotten. The openai response usually takes 30 seconds to 1 minute. What is the reason that the frontend logs an 503 Error Status while the backend logs no errors? When I run the backend in the local, since the response can be awaited forever, no errors are logged. Given the sufficient timeout limits I have set for the two resources, what is the cause of this error?

Many thanks for any helpful advice.

2 Answers
1

Hi. Could you share your network response from Browser? Especially response headers.

answered 2 years ago

  • Omg, it is related to CloudFront!!!! Thanks for asking me to check the header! Your answer helped me identify the root cause! Million thanks!!!!

    Content-Length: 945 Date: Mon, 23 Sep 2024 11:06:33 GMT Via: 1.1 73e8a4e0d7a6505c14ca295a546bcf8e.cloudfront.net (CloudFront) x-amz-cf-id: lUNEAiVf_pNsmSp2JC9sqFP28DzFUq_6MJ4jJ_JChsjio1ET1-Q_8A== x-amz-cf-pop: SFO5-P3 x-cache: Error from cloudfront

  • However, I have checked everything about Cloudfront, I don't see I have set up anything that is causing the problem

0

When creating a new REST API in Amazon API Gateway and selecting Edge-optimized as the endpoint type, this setting ensures that API requests are routed through the nearest CloudFront Point of Presence (PoP) to the client. Seems like the timeout comes from the automatic setup of nearest CloudFront Point of Presence (PoP) to the client.

answered 2 years ago

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.