2

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"
}
Ronak Shah
  • 51
  • 1
  • 4

2 Answers2

2

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!

Ronak Shah
  • 51
  • 1
  • 4
0

You are creating a user with the role User. This is because you have -r User in the command.

Now Airflow requires at least Viewer permissions for the end point you are calling. You can find that information on the Apache Airflow website here.

If you change your command it will work. Change it from

airflow users create -u lambda_user -p some_pwd -f Lambda -l User -r User -e someone@nowhere.com

to

airflow users create -u lambda_user -p some_pwd -f Lambda -l User -r Viewer -e someone@nowhere.com
Jorrick Sleijster
  • 935
  • 1
  • 9
  • 22
  • Actually I got it working after removing Authorization from header. However, looks like **used** API is just to get list of runs for the dag. I need to find the api or function that instead allows to **trigger** the DAG. – Ronak Shah Oct 22 '21 at 15:33