CloudSQLDatabaseHook

Google

Serves DB connection configuration for Google Cloud SQL (Connections of gcpcloudsqldb:// type).

View on GitHub

Last Updated: Mar. 3, 2023

Access Instructions

Install the Google provider package into your Airflow environment.

Import the module into your DAG file and instantiate it with your desired params.

Parameters

gcp_cloudsql_conn_idURL of the connection
gcp_conn_idThe connection ID used to connect to Google Cloud for cloud-sql-proxy authentication.
default_gcp_project_idDefault project id used if project_id not specified in the connection URL

Documentation

Serves DB connection configuration for Google Cloud SQL (Connections of gcpcloudsqldb:// type).

The hook is a “meta” one. It does not perform an actual connection. It is there to retrieve all the parameters configured in gcpcloudsql:// connection, start/stop Cloud SQL Proxy if needed, dynamically generate Postgres or MySQL connection in the database and return an actual Postgres or MySQL hook. The returned Postgres/MySQL hooks are using direct connection or Cloud SQL Proxy socket/TCP as configured.

Main parameters of the hook are retrieved from the standard URI components:

  • user - User name to authenticate to the database (from login of the URI).

  • password - Password to authenticate to the database (from password of the URI).

  • public_ip - IP to connect to for public connection (from host of the URI).

  • public_port - Port to connect to for public connection (from port of the URI).

  • database - Database to connect to (from schema of the URI).

  • sql_proxy_binary_path - Optional path to Cloud SQL Proxy binary. If the binary is not specified or the binary is not present, it is automatically downloaded.

Remaining parameters are retrieved from the extras (URI query parameters):

  • instance - Name of the instance of the Cloud SQL database instance.

  • location - The location of the Cloud SQL instance (for example europe-west1).

  • database_type - The type of the database instance (MySQL or Postgres).

  • use_proxy - (default False) Whether SQL proxy should be used to connect to Cloud SQL DB.

  • use_ssl - (default False) Whether SSL should be used to connect to Cloud SQL DB. You cannot use proxy and SSL together.

  • sql_proxy_use_tcp - (default False) If set to true, TCP is used to connect via proxy, otherwise UNIX sockets are used.

  • sql_proxy_version - Specific version of the proxy to download (for example v1.13). If not specified, the latest version is downloaded.

  • sslcert - Path to client certificate to authenticate when SSL is used.

  • sslkey - Path to client private key to authenticate when SSL is used.

  • sslrootcert - Path to server’s certificate to authenticate when SSL is used.

param gcp_cloudsql_conn_id

URL of the connection

param gcp_conn_id

The connection ID used to connect to Google Cloud for cloud-sql-proxy authentication.

param default_gcp_project_id

Default project id used if project_id not specified in the connection URL

Was this page helpful?