-1

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?
asked Nov 7 at 12:58
5
  • 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. Commented 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. Commented Nov 7 at 15:43
  • Review API Gateway logs (see here). Commented 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. Commented 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. Commented Nov 8 at 12:56

1 Answer 1

0

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.

answered Nov 7 at 15:23
Sign up to request clarification or add additional context in comments.

8 Comments

Thanks, this makes sense. I’ve enabled API Gateway execution/access logs with $context.integrationErrorMessage to capture integration-level errors. I’ll monitor the logs and update the post once I identify what’s causing the intermittent 500s.
atish.s please check this comment
I checked the API Gateway and CloudWatch, but I’m not seeing any integration error logs, the logs aren’t showing up in AWS even when the 500 error occurs
can you see the regular logs of the api gateway or no logs at all?
I can see all the logs, but when a server error occurs, that specific API’s log isn’t getting recorded
In the article I shared, it said this "Your logs might include a different error message that indicates that there's a problem with your Lambda function code. In that case, check your Lambda function code, and verify that your Lambda function returns a response in the required format. If your logs don't include an error message, add $context.error.message and $context.error.responseType to your log format for more information to help troubleshoot.", did you try that as well?
Yeah, but it works sometimes and fails other times with a server error. If there’s a problem in my Lambda function, why does it succeed occasionally?
I do not know, I was just exploring the options.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.