authenticationairflowdirected-acyclic-graphsairflow-2.xairflow-api

Triggering Airflow DAG via API


I have installed Airflow 2.0.1 on EC2 with PostgreSQL RDS as metadata db. I want to trigger DAG from Lambda so tried to test the code with curl but am receiving Unauthorized as response. What if anything should I be doing differently?

Steps:

  1. Create user for lambda
airflow users create -u lambda_user -p some_pwd -f Lambda -l User -r User -e someone@nowhere.com
  1. Define variables on shell (for lambda user, password and endpoint url)
  2. Make the curl call
curl -H "Authorization: Basic Base64(username:password)" -H "Content-type: application/json" -H "Accept: application/json" -X GET --user "${LAMBDA_USER}:${LAMBDA_PWD}" "${ENDPOINT_URL}/api/v1/dags/sns_test/dagRuns"

Response I receive is this:

{
 "detail": null,
 "status": 401,
 "title": "Unauthorized",
 "type": "https://airflow.apache.org/docs/2.0.1/stable-rest-api-ref.html#section/Errors/Unauthenticated"
}

Solution

  • After revising call to

    curl -H "Content-type: application/json" -H "Accept: application/json"
    -X POST --user "${LAMBDA_USER}:${LAMBDA_PWD}" "${ENDPOINT_URL}/api/v1/dags/sns_test/dagRuns" -d '{"conf": {}}'
    

    dag was triggered!