Last active
February 4, 2021 20:30
-
-
Save garystafford/8e9de7f33a90b151af84d84d2820bbd0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# MWAA: Trigger an Apache Airflow DAG using SDK | |
# Author: Gary A. Stafford (February 2021) | |
import logging | |
import boto3 | |
import requests | |
logging.basicConfig( | |
format='[%(asctime)s] %(levelname)s - %(message)s', level=logging.INFO) | |
mwaa_client = boto3.client('mwaa') | |
ENVIRONMENT_NAME = 'Your_Airflow_Environment_Name' | |
DAG_NAME = 'your_dag_name' | |
CONFIG = '{"foo": "bar"}' | |
def main(): | |
response = mwaa_client.create_cli_token( | |
Name=ENVIRONMENT_NAME | |
) | |
logging.info('response: ' + str(response)) | |
token = response['CliToken'] | |
url = 'https://{0}/aws_mwaa/cli'.format(response['WebServerHostname']) | |
headers = {'Authorization': 'Bearer ' + token, 'Content-Type': 'text/plain'} | |
payload = 'trigger_dag {0} --conf {1}'.format(DAG_NAME, CONFIG) | |
response = requests.post(url, headers=headers, data=payload) | |
logging.info('response: ' + str(response)) # should be <Response [200]> | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment