I had a similar problem with MWAA. I had two option to create the connection:
- using Airflow CLI. To simplify creating it with CLI, I suggest to generate it with python, then run the script in your CLI:
import json
from airflow.models.connection import Connection
connection_extra = {
"extra__google_cloud_platform__key_path":"path/to/key",
"extra__google_cloud_platform__key_secret_name": "key_file_name_if_it_is_stored_in_secret_manager",
"extra__google_cloud_platform__keyfile_dict":"{"
"\"type\": \"service_account\","
" \"project_id\": \"<PROJECT_ID>\","
" \"private_key_id\": \"<PRIVATE_KEY_ID>\","
" \"private_key\": \"-----BEGIN PRIVATE KEY-----\\n<PRIVATE_KEY>\\n-----END PRIVATE KEY-----\\n\","
" \"client_email\": \"<CLIENT_EMAIL>\","
" \"client_id\": \"<CLIENT_ID>\","
" \"auth_uri\": \"https://<AUTH_URI>\","
" \"token_uri\": \"https://<TOKEN_URI>\","
" \"auth_provider_x509_cert_url\": \"https://<AUTH_CERT_URI>\","
" \"client_x509_cert_url\": \"https://<CLIENT_CERT_URI>\""
"}",
"extra__google_cloud_platform__num_retries":"5",
"extra__google_cloud_platform__project":"PROJECR_NAME",
"extra__google_cloud_platform__scope":"https://www.googleapis.com/auth/cloud-platform"
}
c = Connection(
conn_id="gcp_conn",
conn_type="google-cloud-platform",
description="A connection to access GCP resources",
extra=connection_extra
)
my_connection_json = {
"conn_type": c.conn_type,
"login": c.login,
"password": c.password,
"host":c.host,
"port": c.port,
"schema": c.schema,
"extra": c.extra
}
print(f"airflow connections add '{c.conn_id}' --conn-json '{json.dumps(my_connection_json)}'")
You can run this script on your scheduler host, it will be print an Airlfow CLI command, copy, paste and run it in a terminal to create the connection.
- from the UI with type
http
(you are not supposed to set all the variables), you can check this doc:
{
"extra__google_cloud_platform__project":"<POJECT NAME>",
"extra__google_cloud_platform__key_path":"",
"extra__google_cloud_platform__keyfile_dict":{
"type":"service_account",
"project_id":"<PROJECT ID>",
"private_key_id":"<PRIVATE KEY ID>",
"private_key":"-----BEGIN PRIVATE KEY-----\n<PRIVATE KEY>\n-----END PRIVATE KEY-----\n",
"client_email":"<CLIENT EMAIL>",
"client_id":"<CLIENT ID>",
"auth_uri":"https://<AUTH URI>",
"token_uri":"https://<TOKEN URI>",
"auth_provider_x509_cert_url":"https://<AUTH CERT URI>",
"client_x509_cert_url":"https://<CLIENT CERT URI>"
},
"extra__google_cloud_platform__scope":"",
"extra__google_cloud_platform__num_retries":"10"
}
You can also create it using an environment variable, but it's not secure:
export AIRFLOW_CONN_GOOGLE_CLOUD_DEFAULT='google-cloud-platform://?extra__google_cloud_platform__project=<PROJECT_NAMR>&extra__google_cloud_platform__scope=<SCOPE>&extra__google_cloud_platform__key_path=<KEY_PATH>&extra__google_cloud_platform__num_retries=10'