Getting 502 errors from service gateway

I have two service stack api’s that are hosted in Api Gateway in aws. I have a service gateway set between the two and occasionally when making calls I am getting the following exception/response:

ServiceStack.ServiceClientBase: System.Net.WebException: The remote server returned an error: (502) Bad Gateway.
   at System.Net.HttpWebRequest.GetResponse()
   at ServiceStack.ServiceClientBase.Send[TResponse](String httpMethod, String relativeOrAbsoluteUrl, Object request) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack.Client\ServiceClientBase.cs:line 1346 

Any thoughts as to why this might be occuring or what I might do to get more information?

Hi @mikeg,

Could you share where the applications are running? (Lambda, EC2, other?) and any other context about how they are setup in API GateWay.

If you’ve able to dump/log/store the whole raw request of the failure, it might point to more of a specific source. Eg, usually AWS managed services put headers with trace IDs and others that might give you a better idea on tracking down the source of the problem.

Any other details on your infra setup with these two applications calling each other would help, lots of ways things can be setup in AWS :slightly_smiling_face:.

A bad gateway error from a HTTP Client means the request to the downstream server (behind the proxy or Gateway) failed. Ideally you’d want to look at the HTTP headers of the downstream request (e.g Gateway to downstream server), otherwise inspect the HTTP Error Response’s Headers & Response from the endpoint you’re calling for potential info on the cause of the failure.

Currently running both api’s out in API Gateway in a lambda proxy. Suspect this may be an issue with cloudfront cert(s) I will update this post with more details as I find them. Thanks for the quick response!

Ended up being a combination of an uncaught exception masking an authorization problem. Got that cleared up and everything works as expected! Thanks for the help!