我正在使用气流来调度AWS上的工作负载。如果失败,我将发送电子邮件。为了通过firehorse获取事件,我想放置一个配置集。但是,我还没有找到配置SES配置集的好方法。
我已经发现我可以通过env var:AIRFLOW__EMAIL__EMAIL_BACKEND=airflow.contrib.utils.icecube.airflow_amazon_ses.send_email
放置电子邮件后端
这是我在dag.py文件中的代码
default_args = {
'owner': OWNER,
'depends_on_past': False,
'start_date': START_DATE,
'email': [ EMAIL ],
'email_on_failure': True,
'email_on_retry': False,
'on_retry_callback': chat_notificator_fn_builder('Will retry the task', color='yellow', conf=config),
'on_failure_callback': chat_notificator_fn_builder('Task failed!', color='red', conf=config),
# https://airflow.apache.org/concepts.html#slas
'sla': timedelta(days=1),
'retries': 0,
'max_active_runs': 1,
'task_concurrency': 1,
# https://airflow.readthedocs.io/en/latest/scheduler.html#backfill-and-catchup
'catchup': False,
'retry_delay': timedelta(minutes=5),
}
dag = DAG(
DAG_NAME,
default_args=default_args,
description='Scheduled mailtest2 Jupyter notebook',
schedule_interval=SCHEDULE_INTERVAL
)
mailtest2_task = JupyterOperator(
task_id='mailtest2_task',
source_notebook_path=SOURCE_NOTEBOOK_PATH,
output_path=OUTPUT_PATH,
retries=0,
dag=dag)
如果您希望接收默认情况下使用SES的气流电子邮件,请将airflow.cfg的电子邮件部分更改为以下内容:
[email]
email_backend = airflow.utils.email.send_email_smtp
[smtp]
# If you want airflow to send emails on retries, failure, and you want to use
# the airflow.utils.email.send_email_smtp function, you have to configure an
# smtp server here
smtp_host = emailsmtpserver.region.amazonaws.com
smtp_starttls = True
smtp_ssl = False
# Uncomment and set the user/pass settings if you want to use SMTP AUTH
smtp_user = SES_AWS_ACCESS_KEY
smtp_password = SES_SECRET_ACCESS_KEY
smtp_port = 25
smtp_mail_from = [email protected] (Use a verified SES email if you are in sandbox!)