MWAA Airflow connection not defined

0

I get the following error when Airflow tries to import my DAG file on MWAA:

Broken DAG: [/usr/local/airflow/dags/file.py] Traceback (most recent call last):
  File "/usr/local/airflow/.local/lib/python3.11/site-packages/airflow/hooks/base.py", line 72, in get_connection
    conn = Connection.get_connection_from_secrets(conn_id)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/airflow/.local/lib/python3.11/site-packages/airflow/models/connection.py", line 477, in get_connection_from_secrets
    raise AirflowNotFoundException(f"The conn_id `{conn_id}` isn't defined")
airflow.exceptions.AirflowNotFoundException: The conn_id `test` isn't defined

However, the connection was clearly defined in the Web UI:

Enter image description here

We try to access the connection like this in the DAG file:

from airflow.providers.mysql.hooks.mysql import MySqlHook
mysql_hook = MySqlHook(mysql_conn_id='test')

Locally, in our Airflow development environment everything works fine, so we can exclude any issues related to the code.

1 Answer
0

The name of the parameter is conn_id[1] not mysql_conn_id --the latter is the example string[2].

mysql_hook = MySqlHook(conn_id='test')

[1] https://github.com/apache/airflow/blob/v2-0-stable/airflow/hooks/base.py#L62C16-L62C23

[2] https://github.com/apache/airflow/blob/v2-0-stable/airflow/providers/mysql/hooks/mysql.py#L42

AWS
John_J
answered 5 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions