Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

FastAPI deployed on Cloud Run returning 413 and requests not coming in.

Hi all,

I have a microservice developed using FastAPI and it is deployed on a Cloud Run Service.

I'm having two issues currently and they are the following:

Issue 1

I'm sending a large GET request with around 5000 values for a query parameter and I'm getting a 413 back from the deployed service. At the same time, I've started the same microservice locally on my laptop, sent the same request getting a 200 back with the expected response content.

Is there some configuration on the Cloud Run Services that is limiting the request's length?

Issue 2

There are other GET requests with between 2000 and 4000 values for the query parameter that are being processed without issues locally for the same microservice but once deployed on Cloud Run, these requests are not even reaching the Cloud Run Service.

I have noticed this since I've added some logs to measure performance in the endpoints and these entries are not appearing in the service's logs. The deployed service is only working with requests that have around 1000 values max. for the query parameter.

 

I've been trying to search for similar issues or specifications in terms of request's length or so but sadly haven't found anything that helps.

 

Has anybody experienced similar issues or does someone have any ideas or suggestions?

 

Thanks!

Jaime

 

 

Solved Solved
0 4 2,851
1 ACCEPTED SOLUTION

The reason you got the 413 status is probably because Cloud Run is protected by the GFE. I can't find any official documentation, but I'll tell you the general case. It's not a good practice to use that much data as a query parameter. In that case, split the request and send it or use the POST method.

View solution in original post

4 REPLIES 4

for #1 my assumption is you created a service - that will provide a Cloud Run URL in the console - Have you tested your service from that URL?

Regardless if local is working - when you deploy you need to verify with the endpoint url with cloud run. If your app is not getting the telemetry for the API request ensure to add the google-python-cloud-debugger library to your requirements

Quickstart: Deploy a Python service to Cloud Run  |  Cloud Run Documentation  |  Google Cloud

We have several microservices already deployed and being used.

I think it is just that the request are being blocked or ignored by the cloud run services due to their length. Sadly, this was nowhere to be found in any documentation so far.

The reason you got the 413 status is probably because Cloud Run is protected by the GFE. I can't find any official documentation, but I'll tell you the general case. It's not a good practice to use that much data as a query parameter. In that case, split the request and send it or use the POST method.

I've just found this information also in stackoverflow but couldn't find any official documentation either.

For our use cases it is necessary having this amount of parameters since we are working with analytics and have multiple filters and variables associated to the endpoints and calculations in background. We have just made the decision to change our requests to POST since we can't have a workaround for the limitation from GFE.

Thanks for the info!