I am trying to run the example in Google Cloud Composer documentation on and I find issues, mainly two:
the environment variables, when created via the gcloud command line or the web interface, do not propagate to the Airflow layer, making that the DAG fails complaining "Variable gcs_bucket do not exist". If I add the variables from the Airflow UI, then it works.
the DAG is executed correctly but at no stage do I see the group of links one would see in Airflow (Tree, Graph, ... ). Even after the execution having finished successfully.
I have checked the service accounts (created by default with the environment) have permissions to edit and update variables (Editor Role) also for access via API.
I have found the documentation is not very up-to-date and for example to create the variable I need to use:
gcloud composer environments update test-environment \
--location=us-central1 \
--update-env-variables=gcs_bucket=gs://airflow2
instead of what the article says.
What else shall I check? What else has changed since the doc was written?
EDIT: A related problem was described here that seems to solve the second problem.
EDIT: Interestingly enough, if I run this free lab, the second problem does not happen. The first one still does. I am comparing the roles in one and the other starting with the not related to the composer project created automatically. And there is no service account created in the format of the alternate solution.
I will appreciate any help anyone could provide.
As of Airflow v1.10.10 (available in Composer as of Sept 17 2020), environment variables in all-uppercase that follow the format AIRFLOW_VAR_<VARIABLE_NAME>
will be available to Airflow as Airflow variables named <variable_name>
, in lowercase.
For example:
AIRFLOW_VAR_GCS_BUCKET="example-bucket-name"
...would result in
models.Variable.get("gcs_bucket") # --> example-bucket-name
You can also use Secret Manager to store Airflow connections, secrets, and variables now. (Documentation)
Do you have the role 'composer.worker' assigned to your service account? With me the dags then show up in the UI.
One very important note 'environment_variables' are not the same as a Variable in airflow. So updating your environment variable will not work, although you could use a environment variable instead of airflow Variables. The Airflow Variables can indeed be assigned via the UI.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With