Apache Airflow Alibaba Cloud Provider

3.3.7 · active · verified Sun Apr 12

The Apache Airflow Alibaba Cloud Provider enables integration with various Alibaba Cloud services such as Object Storage Service (OSS), DataWorks, DirectMail, and more. It provides hooks, operators, and sensors to incorporate Alibaba Cloud workflows into Airflow DAGs. This provider is currently at version 3.3.7 and receives updates typically aligned with Apache Airflow's release cycle or as individual feature/bugfix releases.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates sending an email using the `DirectMailSendMailOperator`. It requires an 'Alibaba Cloud' connection named `alibaba_cloud_default` to be configured in Airflow with appropriate credentials and region. Replace placeholder emails and ensure the sender is a verified DirectMail account.

from __future__ import annotations

import pendulum

from airflow.models.dag import DAG
from airflow.providers.alibaba.cloud.operators.directmail import DirectMailSendMailOperator

# Before running this DAG:
# 1. Create an Airflow Connection:
#    - Conn Id: 'alibaba_cloud_default'
#    - Conn Type: 'Alibaba Cloud'
#    - Host: 'https://dm.cn-hangzhou.aliyuncs.com' (or your DirectMail endpoint)
#    - Login: YOUR_ALIYUN_ACCESS_KEY_ID
#    - Password: YOUR_ALIYUN_ACCESS_KEY_SECRET
#    - Extra: {'region': 'cn-hangzhou'} (or your service region)
# 2. Ensure 'account_name' is a verified sender email in your Alibaba DirectMail console.
# 3. Replace 'recipient@example.com' with an actual recipient.

with DAG(
    dag_id="alibaba_directmail_send_example",
    schedule=None,
    start_date=pendulum.datetime(2023, 10, 26, tz="UTC"),
    catchup=False,
    tags=["alibaba", "directmail", "example"],
) as dag:
    send_mail_task = DirectMailSendMailOperator(
        task_id="send_test_email",
        conn_id="alibaba_cloud_default",
        account_name="no-reply@your-domain.com",  # Your verified sender address
        from_alias="Airflow Notification",
        to_address="recipient@example.com",      # Recipient email
        subject="Airflow Test Email from Alibaba DirectMail",
        html_body="This is a test email sent from Apache Airflow using Alibaba Cloud DirectMail.",
        region="cn-hangzhou",                    # Must match your DirectMail service region
    )

view raw JSON →