【问题标题】:How to disable Airflow DAGs with AWS Lambda如何使用 AWS Lambda 禁用 Airflow DAG
【发布时间】:2022-07-05 15:16:01
【问题描述】:

我需要使用 AWS Lambda 或其他方式禁用 Airflow DAG。我可以使用 python 代码来做到这一点吗?提前谢谢你。

【问题讨论】:

    标签: python aws-lambda airflow


    【解决方案1】:

    您可以使用 Airflow Rest API 暂停/取消暂停 DAG 相关端点是update a DAG

    https://airflow.apache.org/api/v1/dags/{dag_id}
    

    与:

    {
      "is_paused": true
    }
    

    您还可以使用 Airflow 官方 python client 与 API 进行交互。示例:

    import time
    import airflow_client.client
    from airflow_client.client.api import dag_api
    from airflow_client.client.model.dag import DAG
    from airflow_client.client.model.error import Error
    from pprint import pprint
    configuration = client.Configuration(
        host = "http://localhost/api/v1"
    )
    # Configure HTTP basic authorization: Basic
    configuration = client.Configuration(
        username = 'YOUR_USERNAME',
        password = 'YOUR_PASSWORD'
    )
    with client.ApiClient(configuration) as api_client:
        # Create an instance of the API class
        api_instance = dag_api.DAGApi(api_client)
        dag_id = "dag_id_example" # str | The DAG ID.
        dag = DAG(
            is_paused=True,
        )
        try:
            # Update a DAG
            api_response = api_instance.patch_dag(dag_id, dag)
            pprint(api_response)
        except client.ApiException as e:
            print("Exception when calling DAGApi->patch_dag: %s\n" % e)
    

    您可以在客户端doc中查看完整示例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-16
      • 1970-01-01
      • 2020-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-31
      相关资源
      最近更新 更多