Cloud Run: <Cloud SQL instance IP address>: 3306: connect: connect timed out


KATUO :

I want to connect Cloud SQL in Cloud Run Application. I have used golang. Here is the code around the SQL connection setup.

func getEnv(key, def string) string {
    v := os.Getenv(key)
    if v == "" {
        return def
    }
    return v
}
        DB: DB{
            User:     getEnv("DB_USER", "<user name>"),
            Pass:     getEnv("DB_PASS", "<password>"),
            Host:     getEnv("DB_HOST", "0.0.0.0"),
            Port:     getEnv("DB_PORT", "3306"),
            Database: getEnv("DB_DATABASE", "<database name>"),
        },
    dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8&parseTime=true",
        config.DB.User, config.DB.Pass, config.DB.Host, config.DB.Port, config.DB.Database)

    db, err := gorm.Open("mysql", dsn)

I have environment variables set on the Cloud Run settings console. After delpoy the app, the Cloud Run console shows up Cloud Run error: Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable. Logs for this revision might contain more information.and dial tcp <Cloud SQL Private IP> :3306: connect: connection timed outI wonder if the SQL connection is wrong...

AhmetB-Google:

You didn't mention the term "VPC" in your question, so I'm assuming you don't use it.

Cloud Run cannot connect directly to the private IP of the Cloud SQL instance. You need to configure the Serverless VPC Access connector and specify it when deploying your Cloud Run application.

Cloud Run containers are not part of a VPC by default, so unless you do this, they won't have access to the private network.

Related


Google Cloud SQL instance wrong IP address

Rick I'm currently trying to assign another IP address to my Google Cloud SQL instance in order to connect to my database remotely. However, I keep getting the error "Your changes cannot be saved". I tried to add the IP address from the "Edit" option as well a

Cloud Run connect to Cloud SQL module error Python

David Draper I am getting an error when trying to connect to Cloud Run and I am getting the following error. Any ideas? __import__("pg8000") ModuleNotFoundError: No module named 'pg8000' import pandas as pd import sqlalchemy import datetime import requests f

Cloud Run connect to Cloud SQL module error Python

David Draper I am getting an error when trying to connect to Cloud Run and I am getting the following error. Any ideas? __import__("pg8000") ModuleNotFoundError: No module named 'pg8000' import pandas as pd import sqlalchemy import datetime import requests f

Cloud Run connect to Cloud SQL module error Python

David Draper I am getting an error when trying to connect to Cloud Run and I am getting the following error. Any ideas? __import__("pg8000") ModuleNotFoundError: No module named 'pg8000' import pandas as pd import sqlalchemy import datetime import requests f

Connect Google Cloud Run Service to Google Cloud SQL Database

Giulio I have 2 Google Cloud services: Google Cloud Run Service (Node Js / Strapi) Google Cloud SQL Service (Mysql) I have added the UI's Cloud SQL connection to Google Cloud Run Service and I have the public IP of Google Cloud SQL Service. On top of that, I'v

How to securely connect to Cloud SQL from Cloud Run?

Gabidavia How can I connect to a database on Cloud SQL without adding my credential file inside the container? Strom Update: To connect to Cloud SQL from Cloud Run, see the official documentation The fully managed version of Cloud Run now supports Cloud SQL (C

Cloud Run connect to Cloud SQL module error Python

David Draper I am getting an error when trying to connect to Cloud Run and I am getting the following error. Any ideas? __import__("pg8000") ModuleNotFoundError: No module named 'pg8000' import pandas as pd import sqlalchemy import datetime import requests f

Connect Google Cloud Run Service to Google Cloud SQL Database

Giulio I have 2 Google Cloud services: Google Cloud Run Service (Node Js / Strapi) Google Cloud SQL Service (Mysql) I have added the UI's Cloud SQL connection to Google Cloud Run Service and I have the public IP of Google Cloud SQL Service. On top of that, I'v

Connect Google Cloud Run Service to Google Cloud SQL Database

Giulio I have 2 Google Cloud services: Google Cloud Run Service (Node Js / Strapi) Google Cloud SQL Service (Mysql) I have added the UI's Cloud SQL connection to Google Cloud Run Service and I have the public IP of Google Cloud SQL Service. On top of that, I'v

EF Core connect to Google Cloud SQL from Google Cloud Run

Alvin Stephen I have tried these: Data Source=/cloudsql/*****:asia-southeast2:*****;Initial Catalog=*****;Integrated Security=False;User ID=sqlserver;Password=MyPassword0!;MultipleActiveResultSets=True That /cloudsql/*****:asia-southeast2:*****'s my instance

Cloud Run connect to Cloud SQL module error Python

David Draper I am getting an error when trying to connect to Cloud Run and I am getting the following error. Any ideas? __import__("pg8000") ModuleNotFoundError: No module named 'pg8000' import pandas as pd import sqlalchemy import datetime import requests f