Connecting App Engine Hosted .NET Core API to GCP Cloud SQL

时间:2019-04-16 22:48:46

标签: mysql google-app-engine .net-core google-cloud-platform

To preface, I can successfully connect to the MySQL database when running the API locally and the mysql DB and app-engine are part of the same project in GCP.

After deploying my API to app engine, the API cannot connect to my MySQL instance on Cloud SQL - I get the following error:

ERR_SPDY_PROTOCOL_ERROR

This is app-settings.json file:

{
  "Logging": {
    "LogLevel": {
      "Default": "Warning"
    }
  },
  "AllowedHosts": "*",
  "ConnectionStrings": {
    "DefaultConnection": "server=XX.XXX.XXX.XXX;port=3306;database=Development;uid=root;password=XXXXXX"
  }
}

This is my app.yaml file:

  runtime: aspnetcore
  env: flex
  service: dtp-api
  env_variables:
    # Replace user, password, database, and instance connection name with the values obtained
    # when configuring your Cloud SQL instance.
    SQLALCHEMY_DATABASE_URI: >-
      mysql+pymysql://USER:PASSWORD@/development?unix_socket=/cloudsql/mydb-1183:europe-north1:development
  beta_settings:
    cloud_sql_instances: mydb-1183:europe-north1:development

USER is set to 'root' and PASSWORD is root's password.

Context is injected as such:

services.AddDbContext<DTPContext>(options =>
            options.UseMySql(Configuration.GetConnectionString("DefaultConnection")));

And called like:

[HttpGet, Route("topics")]
        public IEnumerable<forum_topic> Index()
        {
            return _forumRepo.GetTopics();
        }

Hitting the above end-point causes the error, I have followed the instructions provided by Google online, but with no luck, can anyone point me in the right direction?

Thanks

0 个答案:

没有答案