0
votes

I am trying to use cloud SQL / mysql instance for my APPEngine account. The app is an python django-2.1.5 appengine app. I have created an instance of MYSQL in the google cloud.

I have added the following in my app.yaml file copied from the SQL instance details:

beta_settings:
  cloud_sql_instances: <INSTANCE_CONNECTION_NAME>=tcp:<TCP_PORT>
  • I have given rights for my appengine project xxx-app's owner xxx-[email protected] the Cloud SQL Client rights. I have created a DB user account specific for the app XYZ which can connect to all hosts (* option)

  • My connection details in settings.py are the following:

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': 'my-db',
            'USER': 'appengine',
            'PASSWORD': 'xxx',
            'HOST': '111.111.11.11', # used actual ip
            'PORT': '3306'
        }
    }
DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'HOST': '/cloudsql/<your-project-id>:<your-cloud-sql-instance>',
            'NAME': '<your-database-name>',
            'USER': 'root',
        }
    }
  • I cannot connect from the local as well. However, if I do a Add Network of my local IP and then try to connect the local connects. THe app runs fine locally after adding the network of local IP Address using CIDR notation.

My problems:

  • I am unable to connect to the Cloud sql without adding the AppEngine assigned IP Address. It gives me an error :
OperationalError: (2003, "Can't connect to MySQL server on '0.0.0.0' ([Errno 111] Connection refused)")
  • Where can I find the appengine's assigned IP Address. I dont mind even if it is temporary. I understand if I need static IP Address I will have to create a Compute VM Instance.
1
did you add exception at firewall?Yugandhar Chaudhari
No they are defaults. How can I get the assigned IPAddress of the current container of appengine?Gary

1 Answers

2
votes

App Engine doesn't have any guarantees regarding IP address of a particular instance, and may change at any time. Since it is a Serverless platform, it abstracts away the infrastructure to allow you to focus on your app.

There are two options when using App Engine Flex: Unix domain socket and TCP port. Which one App Engine provides for you depends on how you specify it in your app.yaml:

  • cloud_sql_instances: <INSTANCE_CONNECTION_NAME> provides a Unix socket at /cloudsql/<INSTANCE_CONNECTION_NAME>
  • cloud_sql_instances: <INSTANCE_CONNECTION_NAME>=tcp:<TCP_PORT> provides a local tcp port (127.0.0.1:<TCP_PORT>).

You can find more information about this on the Connecting from App Engine page.