26
loading...
This website collects cookies to deliver better user experience
dag_id
. During the initialization, we specify when to start, scheduled time and so forth. Here is a simple DAG below:from airflow.models import DAG
from airflow.utils.dates import days_ago
dag = DAG(
dag_id="sample_dag",
start_date=days_ago(2),
description="Sample DAG",
schedule_interval='@daily')
dag_id
, the task_id
would need to be unique within the DAG.def function_a (**kwargs):
name = kwargs['name']
return f'hello {name} !!'
first_task = PythonOperator(
task_id="first_task",
python_callable= function_a,
op_kwargs= {'name': 'Fayaz'},
dag= dag)
second_task = DummyOperator(task_id="second_task", dag=dag)
first_task
first and then trigger the second_task
as soon as the first_task completes. So it will look like this:first_task >> second_task
You need to use your AWS Account to perform the next few steps which may incur some charges.
S3 bucket
which must have versions enabled. Available
so click Open Airflow UI.py
file to our s3/dags
location. Copy the below code and put that in a .py
file and save it as demo_dag.py in your local."""
Importing necessary modules
"""
from airflow.models import DAG
from airflow.utils.dates import days_ago
from airflow.operators.dummy_operator import DummyOperator
from airflow.operators.python_operator import PythonOperator
"""
Initializing DAGs
"""
dag = DAG(
dag_id="grepy_sample_dag",
start_date=days_ago(2),
description="DAG which orchestrates a simple ML workflow",
schedule_interval='@daily')
"""
Creating Tasks
"""
def function_a (**kwargs):
name = kwargs['name']
return f'hello {name} !!'
first_task = PythonOperator(
task_id="first_task",
python_callable= function_a,
op_kwargs= {'name': 'Fayaz'},
dag= dag)
second_task = DummyOperator(task_id="second_task", dag=dag)
"""
Dependencies
"""
first_task >> second_task
demo_dag.py
file to your s3/dags folder.