0
0
AirflowHow-ToBeginner · 3 min read

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.

  1. Open Airflow webserver at http://localhost:8080.
  2. Click Admin > Connections.
  3. Click the + (Create) button.
  4. Fill in the form:
    • Conn Id: my_mysql_conn
    • Conn Type: MySQL
    • Host: localhost
    • Login: root
    • Password: root_password
    • Port: 3306
  5. 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

FieldDescriptionExample
Conn IdUnique name for the connectionmy_postgres_conn
Conn TypeType of external systemPostgres, MySQL, HTTP
HostServer address or IPlocalhost
LoginUsername for accessadmin
PasswordPassword for accesssecret
PortPort number of service5432
ExtraAdditional 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.