3

We are using AWS MWAA. We add our DAG.py files to our S3 bucket programatically. They then show up in the UI. However, they are "OFF" and you must click the "ON" button to start them.

EDIT: Also we may sometimes want to turn a DAG that's ON to OFF (programatically)

I am looking to do this programmatically, however I cannot figure out to.

The API does not seem to have it: https://docs.aws.amazon.com/mwaa/latest/userguide/mwaa-actions-resources.html

Boto does not seem to have it: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/mwaa.html

Is it possible to manipulate a DAGs status from OFF/ON ON/OFF via API?

Tommy
  • 12,588
  • 14
  • 59
  • 110

1 Answers1

4

This is not doable via API but you can use is_paused_upon_creation this flag specifies if the dag is paused when created for the first time. If the dag exists already, this flag will be ignored.

You can set is_paused_upon_creation=False in the DAG contractor.

dag = DAG(
    dag_id='tutorial',
    default_args=default_args,
    is_paused_upon_creation=False,
)

Another option is to do it via unpause CLI:

airflow dags unpause [-h] [-S SUBDIR] dag_id
Elad Kalif
  • 14,110
  • 2
  • 17
  • 49
  • if a job is enabled, how do I toggle it though, without deleting it and re creating it, which will make us lose history? – Tommy Apr 14 '21 at 17:05
  • @Tommy you can do that via CLI https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#unpause or via the UI – Elad Kalif Apr 14 '21 at 17:07
  • Yes. See https://dnx.solutions/how-to-use-apache-airflow-cli-with-amazon-mwaa/ – Elad Kalif Apr 15 '21 at 03:47
  • how does the CLI work? as in, if the CLI works, there must be an API for it, no? – Tommy May 16 '21 at 12:49