Introduction
In this blog we learn how to install apache airflow on windows laptop and create our first DAG (Directed Acyclic Graph).
Prerequisite
Install Docker desktop
Insatllation Steps:
Step 1: Download the docker compose file from Airflow
Step 2: Create a folder "apache-airflow"and save the above content in the docker-compose.yaml file
Step 3: Create .env file and save below
AIRFLOW_UID=50000
Step 4: Initialaize the database
docker compose up airflow-init
The account created has the login airflow and the password airflow
Step 5: Run the Airflow
docker compose up
Step 6: try to browse http://localhost:8080/
user: airflow
: airflow
Create First DAG
Step 1: Sample DAG Code : https://airflow.apache.org/docs/apache-airflow/stable/index.html#workflows-as-code
Step 2: Copy the content and create myfirst_dag.py file
from datetime import datetime
from airflow import DAG
from airflow.decorators import task
from airflow.operators.bash import BashOperator
# A DAG represents a workflow, a collection of tasks
with DAG(dag_id="myfirst_dag", start_date=datetime(2022, 1, 1), schedule="0 0 * * *") as dag:
# Tasks are represented as operators
hello = BashOperator(task_id="hello", bash_command="echo hello")
@task()
def airflow():
print("airflow")
# Set dependencies between tasks
hello >> airflow()
Step 3: Store the file at dags folder where we installed the airflow.
Step 4: Make sure the py file stored in the below location.
Step 5: Check after couple of minutes. your dag will be picked up and display at the portal.
Search like below
Step 6: You can enable the DAG now.
Comments