How to capture passed --conf parameter in called DAG in Airflow





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







2















I am trying to run a DAG from REST API and pass some parameters to it. The DAG should be able to catch the parameters and use it. The problem is I am able to trigger the DAG from REST API,but the DAG is not able to catch the parameters passed. Is there a way to achieve this?



I am triggering the DAG from REST API as below.It passes the parameters in --conf



http://abcairflow.com:8090/admin/rest_api/api?api=trigger_dag&dag_id=trigger_test_dag&conf=%7B%22key%22%3A%2


How to capture the values passed in conf value in the called DAG. As far as I know the conf should take the URL encoded JSON format data.



DAG code:`



def run_this_func(**kwargs):
print(kwargs)

run_this = PythonOperator(
task_id='run_this',
python_callable=run_this_func,
dag=dag
)`









share|improve this question





























    2















    I am trying to run a DAG from REST API and pass some parameters to it. The DAG should be able to catch the parameters and use it. The problem is I am able to trigger the DAG from REST API,but the DAG is not able to catch the parameters passed. Is there a way to achieve this?



    I am triggering the DAG from REST API as below.It passes the parameters in --conf



    http://abcairflow.com:8090/admin/rest_api/api?api=trigger_dag&dag_id=trigger_test_dag&conf=%7B%22key%22%3A%2


    How to capture the values passed in conf value in the called DAG. As far as I know the conf should take the URL encoded JSON format data.



    DAG code:`



    def run_this_func(**kwargs):
    print(kwargs)

    run_this = PythonOperator(
    task_id='run_this',
    python_callable=run_this_func,
    dag=dag
    )`









    share|improve this question

























      2












      2








      2








      I am trying to run a DAG from REST API and pass some parameters to it. The DAG should be able to catch the parameters and use it. The problem is I am able to trigger the DAG from REST API,but the DAG is not able to catch the parameters passed. Is there a way to achieve this?



      I am triggering the DAG from REST API as below.It passes the parameters in --conf



      http://abcairflow.com:8090/admin/rest_api/api?api=trigger_dag&dag_id=trigger_test_dag&conf=%7B%22key%22%3A%2


      How to capture the values passed in conf value in the called DAG. As far as I know the conf should take the URL encoded JSON format data.



      DAG code:`



      def run_this_func(**kwargs):
      print(kwargs)

      run_this = PythonOperator(
      task_id='run_this',
      python_callable=run_this_func,
      dag=dag
      )`









      share|improve this question














      I am trying to run a DAG from REST API and pass some parameters to it. The DAG should be able to catch the parameters and use it. The problem is I am able to trigger the DAG from REST API,but the DAG is not able to catch the parameters passed. Is there a way to achieve this?



      I am triggering the DAG from REST API as below.It passes the parameters in --conf



      http://abcairflow.com:8090/admin/rest_api/api?api=trigger_dag&dag_id=trigger_test_dag&conf=%7B%22key%22%3A%2


      How to capture the values passed in conf value in the called DAG. As far as I know the conf should take the URL encoded JSON format data.



      DAG code:`



      def run_this_func(**kwargs):
      print(kwargs)

      run_this = PythonOperator(
      task_id='run_this',
      python_callable=run_this_func,
      dag=dag
      )`






      airflow






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 16 '18 at 14:36









      Jagdish RoutJagdish Rout

      111




      111
























          2 Answers
          2






          active

          oldest

          votes


















          1














          I did not know that you could trigger a DAG with HTTP GET, but I've successfully triggered with conf using POST and following the documentation https://airflow.apache.org/api.html



          For example triggering the dag "trigger_test_dag":



          curl -X POST --data '"conf":"{"key":"value"}"' 
          "http://abcairflow.com:8090/api/experimental/dags/trigger_test_dag/dag_runs"


          Pay attention to the escaping of apostrophes as conf needs to be a string. I guess you can do a base 64 encode, and then decode in the DAG, to the string if you prefer that.






          share|improve this answer































            0














            Unfortunately, this is not a well-documented feature, but there are examples of a DAG triggering another DAG with the conf set and the target DAG using it. See example_trigger_controller_dag and example_trigger_target_dag. DAGs triggered by an operator, REST API, or CLI should all pass the conf parameter in the same way.



            conf is accessible inside the context, so you'll need to make sure you pass provide_context=True when using a PythonOperator.



            def run_this_func(**kwargs):
            print(kwargs['conf'])

            run_this = PythonOperator(
            task_id='run_this',
            python_callable=run_this_func,
            dag=dag,
            provide_context=True,
            )





            share|improve this answer
























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53339912%2fhow-to-capture-passed-conf-parameter-in-called-dag-in-airflow%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              I did not know that you could trigger a DAG with HTTP GET, but I've successfully triggered with conf using POST and following the documentation https://airflow.apache.org/api.html



              For example triggering the dag "trigger_test_dag":



              curl -X POST --data '"conf":"{"key":"value"}"' 
              "http://abcairflow.com:8090/api/experimental/dags/trigger_test_dag/dag_runs"


              Pay attention to the escaping of apostrophes as conf needs to be a string. I guess you can do a base 64 encode, and then decode in the DAG, to the string if you prefer that.






              share|improve this answer




























                1














                I did not know that you could trigger a DAG with HTTP GET, but I've successfully triggered with conf using POST and following the documentation https://airflow.apache.org/api.html



                For example triggering the dag "trigger_test_dag":



                curl -X POST --data '"conf":"{"key":"value"}"' 
                "http://abcairflow.com:8090/api/experimental/dags/trigger_test_dag/dag_runs"


                Pay attention to the escaping of apostrophes as conf needs to be a string. I guess you can do a base 64 encode, and then decode in the DAG, to the string if you prefer that.






                share|improve this answer


























                  1












                  1








                  1







                  I did not know that you could trigger a DAG with HTTP GET, but I've successfully triggered with conf using POST and following the documentation https://airflow.apache.org/api.html



                  For example triggering the dag "trigger_test_dag":



                  curl -X POST --data '"conf":"{"key":"value"}"' 
                  "http://abcairflow.com:8090/api/experimental/dags/trigger_test_dag/dag_runs"


                  Pay attention to the escaping of apostrophes as conf needs to be a string. I guess you can do a base 64 encode, and then decode in the DAG, to the string if you prefer that.






                  share|improve this answer













                  I did not know that you could trigger a DAG with HTTP GET, but I've successfully triggered with conf using POST and following the documentation https://airflow.apache.org/api.html



                  For example triggering the dag "trigger_test_dag":



                  curl -X POST --data '"conf":"{"key":"value"}"' 
                  "http://abcairflow.com:8090/api/experimental/dags/trigger_test_dag/dag_runs"


                  Pay attention to the escaping of apostrophes as conf needs to be a string. I guess you can do a base 64 encode, and then decode in the DAG, to the string if you prefer that.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 19 '18 at 10:17









                  judoolejudoole

                  9331615




                  9331615

























                      0














                      Unfortunately, this is not a well-documented feature, but there are examples of a DAG triggering another DAG with the conf set and the target DAG using it. See example_trigger_controller_dag and example_trigger_target_dag. DAGs triggered by an operator, REST API, or CLI should all pass the conf parameter in the same way.



                      conf is accessible inside the context, so you'll need to make sure you pass provide_context=True when using a PythonOperator.



                      def run_this_func(**kwargs):
                      print(kwargs['conf'])

                      run_this = PythonOperator(
                      task_id='run_this',
                      python_callable=run_this_func,
                      dag=dag,
                      provide_context=True,
                      )





                      share|improve this answer




























                        0














                        Unfortunately, this is not a well-documented feature, but there are examples of a DAG triggering another DAG with the conf set and the target DAG using it. See example_trigger_controller_dag and example_trigger_target_dag. DAGs triggered by an operator, REST API, or CLI should all pass the conf parameter in the same way.



                        conf is accessible inside the context, so you'll need to make sure you pass provide_context=True when using a PythonOperator.



                        def run_this_func(**kwargs):
                        print(kwargs['conf'])

                        run_this = PythonOperator(
                        task_id='run_this',
                        python_callable=run_this_func,
                        dag=dag,
                        provide_context=True,
                        )





                        share|improve this answer


























                          0












                          0








                          0







                          Unfortunately, this is not a well-documented feature, but there are examples of a DAG triggering another DAG with the conf set and the target DAG using it. See example_trigger_controller_dag and example_trigger_target_dag. DAGs triggered by an operator, REST API, or CLI should all pass the conf parameter in the same way.



                          conf is accessible inside the context, so you'll need to make sure you pass provide_context=True when using a PythonOperator.



                          def run_this_func(**kwargs):
                          print(kwargs['conf'])

                          run_this = PythonOperator(
                          task_id='run_this',
                          python_callable=run_this_func,
                          dag=dag,
                          provide_context=True,
                          )





                          share|improve this answer













                          Unfortunately, this is not a well-documented feature, but there are examples of a DAG triggering another DAG with the conf set and the target DAG using it. See example_trigger_controller_dag and example_trigger_target_dag. DAGs triggered by an operator, REST API, or CLI should all pass the conf parameter in the same way.



                          conf is accessible inside the context, so you'll need to make sure you pass provide_context=True when using a PythonOperator.



                          def run_this_func(**kwargs):
                          print(kwargs['conf'])

                          run_this = PythonOperator(
                          task_id='run_this',
                          python_callable=run_this_func,
                          dag=dag,
                          provide_context=True,
                          )






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 16 '18 at 18:11









                          Daniel HuangDaniel Huang

                          2,0921016




                          2,0921016






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53339912%2fhow-to-capture-passed-conf-parameter-in-called-dag-in-airflow%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Florida Star v. B. J. F.

                              Error while running script in elastic search , gateway timeout

                              Adding quotations to stringified JSON object values