Last active
December 11, 2020 16:09
-
-
Save mrshu/254918d73c0cc0aa2c236ee5523c9eb5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import logging | |
import os | |
import json | |
import urllib3 | |
import datetime | |
AIRFLOW_URL = os.environ['AIRFLOW_URL'] | |
DAG_ID = 'my_helpful_dag' | |
LOG_LEVEL = os.environ.get('LOG_LEVEL', 'info').upper() | |
# setup logging to stdout, or just use print() | |
logging.basicConfig(format='%(asctime)s %(levelname)s %(name)s %(message)s') | |
logging.getLogger().setLevel(logging.getLevelName(LOG_LEVEL)) | |
def handler(event, context): | |
http = urllib3.PoolManager() | |
headers = { | |
'Accept': 'application/json', | |
'Content-Type': 'application/json' | |
} | |
logging.info(f'Triggering Airflow DAG {DAG_ID}') | |
url = f'https://{AIRFLOW_URL}/api/experimental/dags/{DAG_ID}/dag_runs' | |
payload = json.dumps({ | |
'run_id': 'lambda_run_' + datetime.datetime.utcnow().isoformat() | |
}) | |
response = http.request( | |
'POST', | |
url=url, | |
body=payload, | |
headers=headers, | |
retries=False | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment