0
0
Apache Airflowdevops~10 mins

Connection management for cloud services in Apache Airflow - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a connection in Airflow using the CLI.

Apache Airflow
airflow connections add my_gcp_conn --conn-type [1] --conn-extra '{"extra__google_cloud_platform__project": "my-project"}'
Drag options to blanks, or click blank then click option'
Agoogle_cloud_platform
Bmysql
Chttp
Daws
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'aws' instead of 'google_cloud_platform' for a GCP connection.
Using 'http' which is for web connections, not cloud services.
2fill in blank
medium

Complete the code to retrieve a connection object in an Airflow DAG.

Apache Airflow
from airflow.hooks.base_hook import BaseHook
conn = BaseHook.get_connection([1])
Drag options to blanks, or click blank then click option'
A'my_gcp_conn'
B'my_aws_conn'
C'http_conn'
D'db_conn'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the connection ID without quotes, causing a NameError.
Using a different connection ID than the one created.
3fill in blank
hard

Fix the error in the code to set the connection password in Airflow's connection object.

Apache Airflow
conn = BaseHook.get_connection('my_gcp_conn')
conn.[1] = 'new_password'
Drag options to blanks, or click blank then click option'
Auser
Bextra
Chost
Dpassword
Attempts:
3 left
💡 Hint
Common Mistakes
Setting the 'user' attribute instead of 'password'.
Trying to set 'extra' which is a JSON string, not a password.
4fill in blank
hard

Fill both blanks to create a connection dictionary for Google Cloud with project and key path.

Apache Airflow
conn = Connection(conn_id='my_gcp_conn', conn_type=[1], extra='{"extra__google_cloud_platform__project": "my-project", "extra__google_cloud_platform__key_path": "[2]"}')
Drag options to blanks, or click blank then click option'
A'google_cloud_platform'
Bmy-key.json
C/path/to/key.json
D'aws'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'aws' as connection type for GCP.
Using just the filename instead of full path for key_path.
5fill in blank
hard

Fill all three blanks to create a connection dictionary with conn_id, conn_type, and extra JSON for AWS.

Apache Airflow
conn = Connection(conn_id=[1], conn_type=[2], extra='{"extra__aws_access_key_id": "[3]"}')
Drag options to blanks, or click blank then click option'
A'my_aws_conn'
B'aws'
CAKIAIOSFODNN7EXAMPLE
D'google_cloud_platform'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'google_cloud_platform' as connection type for AWS.
Not quoting the connection ID or access key.