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

Fail to deploy fastAPI app to Cloud Run

Hello Support Team,

I’m experiencing an issue deploying my FastAPI service to Google Cloud Run. The application works perfectly in my local development environment, but it fails when deployed to Cloud Run.

Here are the details of the setup and the issue:

1. Service Details:

  • Region: europe-west2
  • Source Code Language: Python (FastAPI)
  • Cloud Run Port: 8150 (configured correctly in my Dockerfile)

2. Problem Summary:

  • The service fails to deploy on Cloud Run, even though it works locally.
  • The service makes HTTP calls to another Cloud Run service with URL specified by variable environment `AI_SERVICE_URL`
  • The other service is hosted in the same region (europe-west2) and is reachable via the public internet.

3. Error Details:

  • I am using an async FastAPI endpoint that calls the above external service.
  • The application log indicates a failure during deployment, but it works locally without issues.
  • The error messages seen in the Cloud Run logs are not clear enough to diagnose the problem.

4. Environment Configuration:

  • Python Version: 3.10
  • HTTP Client: httpx.AsyncClient (with a timeout of 10 seconds)
  • Dockerfile: Configured to use EXPOSE 8150 and starts with uvicorn on port 8150.

5. Steps Already Taken:

  • Verified environment variables and secrets (AI_SERVICE_URL, API keys, etc.).
  • Set appropriate permissions for the Cloud Run service account.
  • Increased CPU and memory allocation for the service.
  • Tested with different timeout values for the HTTP client.
  • Checked health check configurations and added a basic /health endpoint.
  • Analyzed Cloud Run logs for deployment errors but found no conclusive information.

6. Questions:

  1. Are there any specific configurations or limits on Cloud Run that could be causing my FastAPI service to fail during deployment?
  2. Could the issue be related to network connectivity between two Cloud Run services in the same region?
  3. Are there additional logs or debugging tools available on Cloud Run that I can use to further investigate this issue?
  4. Is there a possibility of a timeout or network restriction when my service calls an external API from Cloud Run?
  5. Are there any known issues with deploying FastAPI services that use async endpoints on Cloud Run?
Solved Solved
0 1 1,369
1 ACCEPTED SOLUTION

This has been solved

View solution in original post

1 REPLY 1

This has been solved