I’m facing an issue with my React frontend and AWS Lambda backend setup.
When my app makes multiple API calls at the same time, some of them randomly return a 500 Internal Server Error, while others succeed. On the next attempt, the previously failed APIs might work, and a few different ones fail instead there’s no consistent pattern.
Here’s an example response from the browser network tab:
Request URL: https://api.example.com/account/night-audit/business-config
Request Method: GET
Status Code: 500 Internal Server Error
x-amzn-errortype: InternalServerErrorException
x-amzn-requestid: ba6476cd-4310-4eaf-9333-d41123e6654f
I also checked the backend logs in AWS CloudWatch, and for these failed requests, the Lambda function was never triggered, meaning the request didn’t even reach the function handler.
Setup:
- Frontend: ReactJS
- Backend: AWS Lambda (Node.js)
- API Gateway in front of Lambda
- HTTPS endpoint (dev environment)
What I’ve observed:
- The same APIs sometimes succeed and sometimes fail.
- The failed APIs return 500 InternalServerErrorException.
- No corresponding Lambda logs for failed requests.
My Question:
- What could cause intermittent 500 Internal Server Error responses from API Gateway when the Lambda function isn’t even invoked?
- Could this be related to API Gateway limits, throttling, cold starts, or concurrency issues?
-
It looks like you have some sort of race condition occurring in your code. Start by examining the server error log to determine the underlying fault that leads to to the 500 error being returned, then debug the associated code focussing on what happens if a second process calls the code while the first is still running.Tangentially Perpendicular– Tangentially Perpendicular2025年11月07日 15:16:32 +00:00Commented Nov 7 at 15:16
-
@TangentiallyPerpendicular what makes you think this is a race condition in the code? The code, according to the OP, is not even executing in the failing scenario.jarmod– jarmod2025年11月07日 15:43:06 +00:00Commented Nov 7 at 15:43
-
Review API Gateway logs (see here).jarmod– jarmod2025年11月07日 15:45:24 +00:00Commented Nov 7 at 15:45
-
@jarmod This is classic race condition behaviour. Multiple requests failing randomly that subsequently succeed points to a thread conflict in the code somewhere. The OP hasn't posted the entries from the logs that show the actual problem, but I'd put money on some form of race.Tangentially Perpendicular– Tangentially Perpendicular2025年11月07日 19:40:18 +00:00Commented Nov 7 at 19:40
-
Thanks for the suggestions everyone. Just to clarify, in the failed requests, the Lambda function is never invoked, so I suspect the issue is happening within API Gateway before reaching the function. I’ll enable detailed API Gateway execution/access logs with $context.integrationErrorMessage as suggested to see what’s going on.Kishan Dobariya– Kishan Dobariya2025年11月08日 12:56:21 +00:00Commented Nov 8 at 12:56
1 Answer 1
The api gateway might have encountered some issues and is the one sending the error with status code 500.
It is hard to say what is going wrong on the api gateway, however with some additional logging, it becomes easier to figure what is going on.
This article will help to log the error and its description when it happens: https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-troubleshooting-lambda.html
The idea is to log any integration errors which happens on the AWS Lambda level, not on the functions behind it. This is be done by creating a new log group for the api gateway and enriching the logging to include the $context.integrationErrorMessage or $context.integration.error.