What change needs to be made to return a proper error code through the API Gateway?
Enable CORS in the API Gateway method settings
Use a Lambda proxy integration to return HTTP codes and headers
Enable API Gateway error pass-through.
Return the value in the header x-Amzn-ErrorType.
Explanations:
Enabling CORS in API Gateway allows cross-origin requests but does not impact the error handling behavior between Lambda and API Gateway.
Using a Lambda proxy integration allows Lambda to return specific HTTP status codes and headers, which API Gateway will pass through directly. Without this, API Gateway defaults to returning a 200 status code.
Enabling API Gateway error pass-through only affects how API Gateway passes errors from Lambda to the client. However, it doesn’t resolve the issue of Lambda returning an incorrect HTTP status code (200 instead of 4xx).
Returning an error type in the headerx-Amzn-ErrorTypeis useful for error identification but does not affect the HTTP status code returned by API Gateway.