1

I am getting error with status code 503 - Service Unavailable in my OPTIONS request to API Gateway in AWS (Screenshot attached below)

As you can see the OPTIONS request is failing

Our Tech Stack:

  1. API Gateway to route requests to proper docker container(s) residing inside EC2 instance running on docker-compose.
  2. Have enabled VPC peering to connect our application hosted inside the EC2 instance with MongoDB Atlas.

I had a word with the solutions architect at AWS and he said that I've configured the CORS correctly for the API Gateway and it's not a CORS issue. He said that it is an issue on my application hosted on EC2 instance.

My application is hosted in a microservices fashion on docker-compose and consists of 3 microservices. And I am facing this status 503 - Service Unavailable error only on 1 of my microservices out of the 3. The other two microservices are working perfectly fine without any issues.

I am able to see only those requests that had status 200 - OK inside my docker container logs and not those logs which encountered a status 503 - Service Unavailable error.

My API Gateway CORS configuration is as follows:

API Gateway CORS Config

Also, attaching the log generated by the API gateway in Cloudwatch:

{
    "requestId": "P1Zp3iC0BcwEJBA=",
    "ip": "<SOME IP>",
    "requestTime": "31/Mar/2022:05:31:17 +0000",
    "httpMethod": "OPTIONS",
    "routeKey": "ANY /master/{proxy+}",
    "status": "503",
    "protocol": "HTTP/1.1",
    "responseLength": "33",
    "Request_ID": "-",
    "resourcePath": "-"
}

I am not able to figure out the root cause as to why this error is popping up occasionally and not continuously as I have mentioned in the title of this question.

Anuj Panchal
  • 391
  • 3
  • 15
  • You need to investigate why your application is returning 503s, if you aren't logging application requests, now is the time. – Warren Parad Mar 31 '22 at 11:39
  • Okay, do you recommend any specific tool for the same? Right now I am using Cloudwatch logs to visualize the logs of my EC2 instance – Anuj Panchal Mar 31 '22 at 12:30
  • CW logs is great, but you need to make sure you are actually logging what you need to log. This isn't a matter of using a tool, this is a matter of doing the right thing in the code at the right time. It is heavily dependent on the framework you already using. – Warren Parad Apr 09 '22 at 14:08
  • I have found the issue I think. And, the issue is my gunicorn worker is timing out. Any recommendations as to how to mitigate from this issue? – Anuj Panchal Apr 11 '22 at 05:40
  • Why is it timing out? – Warren Parad Apr 12 '22 at 19:23

0 Answers0