创建连接(预览)

适用范围:Azure CLI ml 扩展 v2(最新版)Python SDK azure-ai-ml v2(最新版)

本文介绍如何连接到 Azure 外部的数据源,使该数据可供 Azure 机器学习服务使用。 Azure 连接充当密钥保管库代理,与连接的交互实际上是与 Azure 密钥保管库的直接交互。 Azure 机器学习连接将用户名和密码数据资源作为机密安全地存储在密钥保管库中。 密钥保管库 RBAC 控制对这些数据资源的访问。 为了可以使用此数据,Azure 支持连接到以下外部源:

  • Snowflake DB
  • Amazon S3
  • Azure SQL DB

重要

此功能目前处于公开预览状态。 此预览版在提供时没有附带服务级别协议,我们不建议将其用于生产工作负荷。 某些功能可能不受支持或者受限。

有关详细信息,请参阅适用于 Azure 预览版的补充使用条款

先决条件

重要

Azure 机器学习连接将在连接创建期间传递的凭据安全地存储在工作区 Azure Key Vault 中。 连接从密钥保管库存储位置引用凭据以供后续使用。 将凭据存储在密钥保管库后,无需直接处理凭据。 可以选择将凭据存储在 YAML 文件中。 CLI 命令或 SDK 可能会替代它们。 建议避免将凭据存储在 YAML 文件中,因为安全漏洞可能会导致凭据泄露。

注意

若要成功导入数据,请验证是否已安装适用于 SDK 的最新 azure-ai-ml 包(版本 1.5.0 或更高版本),以及 ml 扩展(版本 2.15.1 或更高版本)。

如果有较旧的 SDK 包或 CLI 扩展,请删除旧包,并使用选项卡部分中显示的代码安装新包。 按照如下所示的 SDK 和 CLI 说明进行操作:

代码版本

az extension remove -n ml
az extension add -n ml --yes
az extension show -n ml #(the version value needs to be 2.15.1 or later)

创建 Snowflake DB 连接

此 YAML 文件创建 Snowflake DB 连接。 请务必更新适当的值:

# my_snowflakedb_connection.yaml
$schema: http://azureml/sdk-2-0/Connection.json
type: snowflake
name: my-sf-db-connection # add your datastore name here

target: jdbc:snowflake://<myaccount>.snowflakecomputing.com/?db=<mydb>&warehouse=<mywarehouse>&role=<myrole>
# add the Snowflake account, database, warehouse name and role name here. If no role name provided it will default to PUBLIC
credentials:
    type: username_password
    username: <username> # add the Snowflake database user name here or leave this blank and type in CLI command line
    password: <password> # add the Snowflake database password here or leave this blank and type in CLI command line

在 CLI 中创建 Azure 机器学习连接:

选项 1:使用 YAML 文件中的用户名和密码

az ml connection create --file my_snowflakedb_connection.yaml

选项 2:在命令行中替代用户名和密码

az ml connection create --file my_snowflakedb_connection.yaml --set credentials.username="XXXXX" credentials.password="XXXXX"

创建 Azure SQL DB 连接

此 YAML 脚本创建 Azure SQL DB 连接。 请务必更新适当的值:

# my_sqldb_connection.yaml
$schema: http://azureml/sdk-2-0/Connection.json

type: azure_sql_db
name: my-sqldb-connection

target: Server=tcp:<myservername>,<port>;Database=<mydatabase>;Trusted_Connection=False;Encrypt=True;Connection Timeout=30
# add the sql servername, port addresss and database
credentials:
    type: sql_auth
    username: <username> # add the sql database user name here or leave this blank and type in CLI command line
    password: <password> # add the sql database password here or leave this blank and type in CLI command line

在 CLI 中创建 Azure 机器学习连接:

选项 1:使用 YAML 文件中的用户名/密码

az ml connection create --file my_sqldb_connection.yaml

选项 2:替代 YAML 文件中的用户名和密码

az ml connection create --file my_sqldb_connection.yaml --set credentials.username="XXXXX" credentials.password="XXXXX"

创建 Amazon S3 连接

使用以下 YAML 文件创建 Amazon S3 连接。 请务必更新适当的值:

# my_s3_connection.yaml
$schema: http://azureml/sdk-2-0/Connection.json

type: s3
name: my_s3_connection

target: <mybucket> # add the s3 bucket details
credentials:
    type: access_key
    access_key_id: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX # add access key id
    secret_access_key: XxXxXxXXXXXXXxXxXxxXxxXXXXXXXXxXxxXXxXXXXXXXxxxXxXXxXXXXXxXXxXXXxXxXxxxXXxXXxXXXXXxXxxXX # add access key secret

在 CLI 中创建 Azure 机器学习连接:

az ml connection create --file my_s3_connection.yaml

后续步骤