0

I'm trying to trigger Airflow's DAG and send parameters inside the post request.

Usage example - DAG has one task that only prints the number sent inside the trigger request.

Example to trigger dag:

import base64
import boto3
import requests

MWAA_ENVIRONMENT_NAME = 'production-mwaa'
dag_name = 'test_param_dag'
mwaa_cli_command = 'dags trigger'

client = boto3.client('mwaa')

mwaa_cli_token = client.create_cli_token(Name=MWAA_ENVIRONMENT_NAME)

mwaa_auth_token = 'Bearer ' + mwaa_cli_token['CliToken']
mwaa_webserver_hostname = f'https://{mwaa_cli_token["WebServerHostname"]}/aws_mwaa/cli'
raw_data = '{0} {1}'.format(mwaa_cli_command, dag_name)

mwaa_response = requests.post(url=mwaa_webserver_hostname,
                          headers=
                          {
                              'Authorization': mwaa_auth_token,
                              'Content-Type': 'text/plain'
                          },
                          params={"x": 11},
                          data=raw_data)

mwaa_std_err_message = base64.b64decode(mwaa_response.json()['stderr']).decode('utf8')
mwaa_std_out_message = base64.b64decode(mwaa_response.json()['stdout']).decode('utf8')

print(mwaa_response.status_code)
print('err:\n' + mwaa_std_err_message)
print('out:\n' + mwaa_std_out_message)

The dag should print the value of 'x' param --> 11.

1 Answer 1

0

You can access the param 'x' inside the dag using "{{ dag_run.conf['x'] }}"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.