How to Create Connection Using UI in Airflow
To create a connection in Airflow using the
UI, open the Airflow webserver, go to Admin > Connections, then click + (Create). Fill in the connection details like Conn Id, Conn Type, and credentials, then save to use it in your DAGs.Syntax
Creating a connection in Airflow UI involves filling out a form with these key fields:
- Conn Id: Unique identifier for the connection.
- Conn Type: Type of service (e.g., MySQL, HTTP, S3).
- Host: Server address.
- Login: Username for authentication.
- Password: Password for authentication.
- Port: Service port number.
- Extra: JSON for additional parameters.
airflow
No code needed; this is a UI form.Example
This example shows how to create a MySQL connection named my_mysql_conn using the Airflow UI.
- Open Airflow webserver at
http://localhost:8080. - Click
Admin>Connections. - Click the
+ (Create)button. - Fill in the form:
- Conn Id: my_mysql_conn
- Conn Type: MySQL
- Host: localhost
- Login: root
- Password: root_password
- Port: 3306
- Click
Save.
This connection can now be referenced in DAGs by my_mysql_conn.
Common Pitfalls
Common mistakes when creating connections in Airflow UI include:
- Using a Conn Id that is not unique, causing conflicts.
- Leaving required fields like Conn Type or Host empty.
- Incorrect credentials causing connection failures.
- Not saving the connection after filling the form.
- Forgetting to restart Airflow webserver if environment variables override connections.
python
Wrong example: # Trying to use a connection without saving it conn = BaseHook.get_connection('unsaved_conn') # This will fail Right example: # Use connection after creating and saving it in UI conn = BaseHook.get_connection('my_mysql_conn') # This works
Output
Exception: Connection not found for conn_id: unsaved_conn
No output (connection object) for saved connection
Quick Reference
| Field | Description | Example |
|---|---|---|
| Conn Id | Unique name for the connection | my_postgres_conn |
| Conn Type | Type of external system | Postgres, MySQL, HTTP |
| Host | Server address or IP | localhost |
| Login | Username for access | admin |
| Password | Password for access | secret |
| Port | Port number of service | 5432 |
| Extra | Additional JSON parameters | {"sslmode": "require"} |
Key Takeaways
Use the Airflow UI under Admin > Connections to create and manage connections easily.
Always provide a unique Conn Id and fill all required fields to avoid errors.
Save the connection after entering details to make it available for DAGs.
Check credentials carefully to ensure successful connection to external services.
Restart Airflow webserver only if environment variables override UI connections.