AWS mwaa: MWAA: email config table updated for Airflow 2.11.2 + custom templates
Summary
Updates the Airflow configuration options table links from 2.0.2 to 2.11.2 docs, documents two new options (email.subject_template, email.html_content_template) for custom Jinja2 email subjects/bodies, and adds a how-to section on uploading template files to the DAGs folder. SMTP rows now cover TLS (STARTTLS) and SSL transport encryption descriptions.
Security assessment
The change is a documentation/version-link refresh plus a new feature section on customizing alert email subject/body templates via Jinja2. The TLS/SSL SMTP wording is pre-existing content whose only diff delta is an updated documentation URL, so no vulnerability, credential handling, or hardening change is introduced. Not security-documenting and no security impact beyond tangential mentions of transport encryption.
Evidence
+smtp.smtp_starttls | Transport Layer Security (TLS) is used to encrypt the email over the internet in [smtp_starttls](https://airflow.apache.org/docs/apache-airflow/2.11.2/configurations-ref.html#smtp-starttls). | True
Diff
diff --git a/mwaa/latest/userguide/configuring-env-variables.md b/mwaa/latest/userguide/configuring-env-variables.md index fed8c8b9a..5f58502c2 100644 --- a//mwaa/latest/userguide/configuring-env-variables.md +++ b//mwaa/latest/userguide/configuring-env-variables.md @@ -32,0 +33,2 @@ Apache Airflow configuration options can be attached to your Amazon Managed Work + * [Customizing the email subject and content](./configuring-env-variables.html#configuring-env-variables-email-customizing) + @@ -135,6 +137,8 @@ Airflow configuration option | Description | Example value -email.email_backend | The Apache Airflow utility used for email notifications in [email_backend](https://airflow.apache.org/docs/apache-airflow/2.0.2/configurations-ref.html#email-backend). | airflow.utils.email.send_email_smtp -smtp.smtp_host | The name of the outbound server used for the email address in [smtp_host](https://airflow.apache.org/docs/apache-airflow/2.0.2/configurations-ref.html#smtp-host). | localhost -smtp.smtp_starttls | Transport Layer Security (TLS) is used to encrypt the email over the internet in [smtp_starttls](https://airflow.apache.org/docs/apache-airflow/2.0.2/configurations-ref.html#smtp-starttls). | True -smtp.smtp_ssl | Secure Sockets Layer (SSL) is used to connect the server and email client in [smtp_ssl](https://airflow.apache.org/docs/apache-airflow/2.0.2/configurations-ref.html#smtp-ssl). | False -smtp.smtp_port | The Transmission Control Protocol (TCP) port designated to the server in [smtp_port](https://airflow.apache.org/docs/apache-airflow/2.0.2/configurations-ref.html#smtp-port). | 587 -smtp.smtp_mail_from | The outbound email address in [smtp_mail_from](https://airflow.apache.org/docs/apache-airflow/2.0.2/configurations-ref.html#smtp-mail-from). | [email protected] +email.email_backend | The Apache Airflow utility used for email notifications in [email_backend](https://airflow.apache.org/docs/apache-airflow/2.11.2/configurations-ref.html#email-backend). | airflow.utils.email.send_email_smtp +email.subject_template | The path to a Jinja2 template file used to render the **subject** of Apache Airflow alert emails in [subject_template](https://airflow.apache.org/docs/apache-airflow/2.11.2/configurations-ref.html#subject-template). If this option is not set, Apache Airflow uses the default subject `Airflow alert: {{ti}}`. | /usr/local/airflow/dags/my_subject_template_file +email.html_content_template | The path to a Jinja2 template file used to render the **body** of Apache Airflow alert emails in [html_content_template](https://airflow.apache.org/docs/apache-airflow/2.11.2/configurations-ref.html#html-content-template). If this option is not set, Apache Airflow uses the default built-in body template. | /usr/local/airflow/dags/my_html_content_template_file +smtp.smtp_host | The name of the outbound server used for the email address in [smtp_host](https://airflow.apache.org/docs/apache-airflow/2.11.2/configurations-ref.html#smtp-host). | localhost +smtp.smtp_starttls | Transport Layer Security (TLS) is used to encrypt the email over the internet in [smtp_starttls](https://airflow.apache.org/docs/apache-airflow/2.11.2/configurations-ref.html#smtp-starttls). | True +smtp.smtp_ssl | Secure Sockets Layer (SSL) is used to connect the server and email client in [smtp_ssl](https://airflow.apache.org/docs/apache-airflow/2.11.2/configurations-ref.html#smtp-ssl). | False +smtp.smtp_port | The Transmission Control Protocol (TCP) port designated to the server in [smtp_port](https://airflow.apache.org/docs/apache-airflow/2.11.2/configurations-ref.html#smtp-port). | 587 +smtp.smtp_mail_from | The outbound email address in [smtp_mail_from](https://airflow.apache.org/docs/apache-airflow/2.11.2/configurations-ref.html#smtp-mail-from). | [email protected] @@ -145,0 +150,54 @@ Use 587 with STARTTLS (`smtp_starttls` : `True`, `smtp_ssl` : `False`), or 465 w +#### Customizing the email subject and content + +By default, Apache Airflow sends alert emails using its built-in subject and body templates. You can override these defaults to send customized notifications. Set the `email.subject_template` and `email.html_content_template` configuration options to point to your own Jinja2 template files. Jinja2 is an open-source templating engine; for more information, see the [Jinja website](https://jinja.palletsprojects.com/). + +###### Note + +Customizing email content requires a working email backend. Configure your SMTP settings as described in the Email configurations table before you customize the subject and body. For example, you can use Amazon Simple Email Service (Amazon SES) as the SMTP host. + +If you do not set `subject_template` and `html_content_template`, Apache Airflow uses the following base templates: + +**Default subject** : + + + Airflow alert: {{ti}} + +**Default HTML content** : + + + Try {{try_number}} out of {{max_tries + 1}}<br> + Exception:<br>{{exception_html}}<br> + Log: <a href="{{ti.log_url}}">Link</a><br> + Host: {{ti.hostname}}<br> + Mark success: <a href="{{ti.mark_success_url}}">Link</a><br> + +###### To use custom templates on Amazon MWAA + + 1. Create your subject and HTML content template files. The following are examples. + +`my_subject_template_file` + + Production Airflow alert: {{ti}} + +`my_html_content_template_file` + + Exception:<br>{{exception_html}}<br> + State: {{ti.state}}<br> + Mark success: <a href="{{ti.mark_success_url}}">Link</a><br> + + 2. Upload the template files to the DAGs folder in your environment's Amazon S3 bucket. Amazon MWAA syncs this folder to `/usr/local/airflow/dags/` on the environment's containers. + + 3. On the Amazon MWAA console, add the `email.subject_template` and `email.html_content_template` configuration options shown in the preceding Email configurations table, pointing each to the container path of the corresponding template file: + +Airflow configuration option | Value +---|--- +email.subject_template | /usr/local/airflow/dags/my_subject_template_file +email.html_content_template | /usr/local/airflow/dags/my_html_content_template_file + + 4. Save your changes. After the environment finishes updating, alert emails use your custom subject and body templates. + + + + +For more information about sending email through Amazon SES as the SMTP host, see the AWS re:Post article [How to send emails from MWAA DAG tasks using SES as the SMTP host](https://repost.aws/articles/AR_qekbw14R5GKsg3G9cWvjA/how-to-send-emails-from-mwaa-dag-tasks-using-ses-as-the-smtp-host). +