I am trying to create a composer environment with the approach of infrastructure as code. For this, I need to store and retrieve airflow variables programmatically and keep them versioned somewhere.
In a previous post, Ed Morton wrote a script to convert the table to a JSON, but there is a problem related to the way composer/airflow outputs the data when using the following command :
gcloud composer environments run `$COMPOSER_ENV` --location <location> connections -- --list
A sample of the output is :
╒════════════════════════════════╤═════════════════════════════╤════════════════════════════════╤════════╤════════════════╤══════════════════════╤════════════════════════════════╕
│ Conn Id │ Conn Type │ Host │ Port │ Is Encrypted │ Is Extra Encrypted │ Extra │
╞════════════════════════════════╪═════════════════════════════╪════════════════════════════════╪════════╪════════════════╪══════════════════════╪════════════════════════════════╡
│ 'airflow_db' │ 'mysql' │ 'airflow-sqlp...rvice.default' │ None │ True │ False │ None │
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┼────────┼────────────────┼──────────────────────┼────────────────────────────────┤
As you can see, the problem is the Host
, and Extra
columns contain an ellipsis ...
that abridges long text such as here 'airflow-sqlp...rvice.default'
.
How do I get a full version of the information output by the above-mentioned (composer
) utility?
I am using composer-1.12.1-airflow-1.10.9
. Unfortunately the nice feature of exporting the connections to a JSON using the CLI is only available in the latest version of airflow.
Am working on Airflow but never used composer. However, from the documentation came to know that
gcloud composer environments run
runs Airflow CLI sub-commands remotely.Airflow CLI has an option to open DB shell
airflow shell
and its capable of receiving input fromstdin
. So I tried to pipe in SQL statement to retrieve connections and it worked.We could also extract the results as
json
orcsv
. Most databases supports it. For example in sqlite:I couldn't try it composer as I don't have a composer environment. This is just a trick that I could think of since current version of Airflow CLI doesn't have configurable output.