如何在 Airflow 中使用电子邮件操作符附加文件

Cha*_*nya 5 google-cloud-platform airflow google-cloud-composer

我使用了参数 files =["abc.txt"]。我从气流文档中获取了信息... https://airflow.readthedocs.io/en/stable/_modules/airflow/operators/email_operator.html

但我收到找不到该文件的错误。我的问题是这个气流将从哪里选择我的文件。是来自 Composer 环境中的 GCS Bucket 还是 DAG 文件夹?

我需要在哪里上传文件以及“文件”参数的正确语法是什么?

提前致谢。

Tla*_*zal 8

这些文件取自本地文件系统,并且 files 参数确实是一个字符串列表,如files =["abc.txt"].

要将文件上传到 Composer,您可以使用Composer 环境 GCS 存储桶中的数据文件夹,然后您可以从/home/airflow/gcs/data/

取自文档的示例,添加了 files 属性,如下:

from airflow.operators import email_operator
    # Send email confirmation
    email_summary = email_operator.EmailOperator(
        task_id='email_summary',
        to=models.Variable.get('email'),
        subject='Sample Email',
        html_content="HTML content",
        files=['/home/airflow/gcs/data/abc.txt'])
Run Code Online (Sandbox Code Playgroud)

您也可以将文件下载到本地系统,然后发送;但是,您需要确保下载的文件和电子邮件操作员由同一工作人员执行