Microsoft Azure Cosmos

Microsoft Azure Cosmos 连接类型启用 Azure Cosmos 集成。

Azure 认证

使用 Airflow 连接到 Azure Cosmos 有三种方法。

  1. 使用主密钥(Primary Keys),即向 Airflow 连接添加特定凭据 (client_id, secret, tenant) 和帐户名。

  2. 通过设置 managed_identity_client_idworkload_identity_tenant_id 来使用托管标识(managed identity)(底层使用带有这些参数的 DefaultAzureCredential)。

  3. 回退到DefaultAzureCredential。这包含一个尝试不同选项进行身份验证的机制:托管系统标识(Managed System Identity)、环境变量、通过 Azure CLI 进行身份验证等。

默认连接 ID

所有与 Microsoft Azure Cosmos 相关的钩子(hooks)和操作符(operators)默认使用 azure_cosmos_default

配置连接

登录

指定用于初始连接的 Cosmos 终结点 URI。

密码(可选)

指定用于初始连接的 Cosmos 主密钥令牌(Cosmos Master Key Token)。可以省略此项,以回退到 DefaultAzureCredential

额外(可选)

指定可在 Azure Cosmos 连接中使用的额外参数(以 JSON 字典形式)。以下参数均为可选:

  • database_name: 指定要使用的 Azure Cosmos 数据库。

  • collection_name: 指定要使用的 Azure Cosmos 集合。

  • partition_key: 指定集合的分区键。

  • subscription_id: 指定用于初始连接的订阅 ID。回退到 DefaultAzureCredential 所必需。

  • resource_group_name: 指定所需 Azure Cosmos 所在的 Azure 资源组名称。回退到 DefaultAzureCredential 所必需。

  • managed_identity_client_id: 用户分配的托管标识的客户端 ID。如果与 workload_identity_tenant_id 一同提供,它们将被传递给 DefaultAzureCredential

  • workload_identity_tenant_id: 应用程序的 Microsoft Entra 租户 ID。也称为其“目录”ID。如果与 managed_identity_client_id 一同提供,它们将被传递给 DefaultAzureCredential

在环境变量中指定连接时,应使用 URI 语法进行指定。

请注意,URI 的所有组成部分都应进行 URL 编码。

例如

export AIRFLOW_CONN_AZURE_COSMOS_DEFAULT='azure-cosmos://https%3A%2F%2Fairflow.azure.com:master%20key@?database_name=mydatabase&collection_name=mycollection'

此条目是否有帮助?