Skip to content

Instantly share code, notes, and snippets.

Query Cloud SQL from Cloud Composer (Apache Airflow) task on GCP

If you need to do a proof of concept on Cloud Composer and Cloud SQL, here are some steps on how to do a SELECT query in Cloud SQL database from Cloud Composer instance - an Apache AirFlow managed service by Google Cloud Platform.

Heads up

The following steps will incur you costs depending on the usage time you have for each instance created (both Cloud SQL and Composer).

1. Create a Cloud Composer cluster (environment)

@fillipo
fillipo / cloud-composer-example.py
Created July 1, 2019 19:54
Cloud Composer (Apache Airflow) Example
#!/usr/bin/python
# -*- coding: utf-8 -*-
from airflow import DAG
# from airflow.operators.bash_operator import BashOperator
from datetime import datetime, timedelta
from airflow.contrib.operators.gcs_download_operator import GoogleCloudStorageDownloadOperator
from airflow.contrib.operators.file_to_gcs import FileToGoogleCloudStorageOperator
@fillipo
fillipo / cloud-composer-example.py
Created July 1, 2019 19:54
Cloud Composer (Apache Airflow) Example
#!/usr/bin/python
# -*- coding: utf-8 -*-
from airflow import DAG
# from airflow.operators.bash_operator import BashOperator
from datetime import datetime, timedelta
from airflow.contrib.operators.gcs_download_operator import GoogleCloudStorageDownloadOperator
from airflow.contrib.operators.file_to_gcs import FileToGoogleCloudStorageOperator
/****
*
* Code based on: https://github.com/dialogflow/fulfillment-webhook-nodejs/blob/master/functions/index.js
* Notice that there are other functions such as "function googleAssistantHandler(agent)" that you
* can use as an example
*
* ***/
'use strict';