🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
đŸ’ŧ Servicesâ„šī¸ Aboutâœ‰ī¸ ContactView Pricing Plansfrom $10

Connection Management and Hooks in Apache Airflow

đŸŸĸ Free Lesson

Advertisement

Connection Management and Hooks

Connection Management ArchitectureAirflow UIAdmin {'>'} ConnectionsREST APIConnection CRUDCLIairflow connectionsMetadata DBConnection TableHook Layerget_connection()S3 Hookaws_defaultPostgres Hookpostgres_defaultHTTP Hookapi_defaultSpark Hookspark_defaultBigQuery Hookgoogle_cloudRedis Hookredis_defaultHooks encapsulate connection logic, handle auth, pooling, and retries

Architecture Diagram

Formal Definitions

Detailed Explanation

Creating Connections

Connections can be created through the Airflow UI, CLI, REST API, or environment variables.


Creation Methods:

MethodCommand/Location
CLIairflow connections add 'my_conn' --conn-type ...
Environment VariableAIRFLOW_CONN_MY_CONN='...'
UIAdmin → Connections → Add
ProgrammaticConnection(conn_id=..., conn_type=...)

Using Hooks

Hooks provide a consistent interface for external system interaction.

Tip: Use connection pools to reduce overhead by 60-80%.


Key Concepts Table

Connection TypeConn TypeHook ClassKey Parameters
PostgreSQLpostgresPostgresHookhost, login, password, schema, port
MySQLmysqlMySqlHookhost, login, password, schema, port
S3awsS3Hooklogin (key), password (secret), extra (region)
GCSgoogle_cloud_platformGCSHookextra (keyfile, project)
HTTPhttpHttpHookhost, schema, extra (headers)

Key Concepts Table

Connection TypeConn TypeHook ClassKey Parameters
PostgreSQLpostgresPostgresHookhost, login, password, schema, port
MySQLmysqlMySqlHookhost, login, password, schema, port
S3awsS3Hooklogin (key), password (secret), extra (region)
GCSgoogle_cloud_platformGCSHookextra (keyfile, project)
HTTPhttpHttpHookhost, schema, extra (headers)
SparksparkSparkHookhost, extra (master, deploy-mode)
RedisredisRedisHookhost, login, password, port, db

Code Examples

Custom Hook Implementation

Connection Pool Configuration

Secrets Backend Integration

Performance Metrics

Connection Types Comparison

AspectMetadata DBEnvironment VariablesSecrets Manager
SecurityMediumHighVery High
PerformanceFast (DB lookup)Fast (OS lookup)Medium (API call)
Audit TrailYesNoYes
RotationManualManualAutomated
CostFreeFreeLow-Medium
ComplexityLowLowMedium
Multi-environmentDifficultEasyEasy

Connection Pool Metrics

MetricRecommendedWarningCritical
Pool Utilization< 70%70-90%> 90%
Connection Wait Time< 1s1-5s> 5s
Connection Errors< 1%1-5%> 5%
Pool Overflow< 50%50-80%> 80%

See Also

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Need Expert Airflow Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement