You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用AZ CLI在PowerShell创建Azure流分析PostgreSQL输出时提示缺少数据源类型

Azure Stream Analytics AZ CLI 创建PostgreSQL输出报错的原因及解决方法

问题情况

在已有Azure Stream Analytics作业和PostgreSQL数据库的环境中,使用PowerShell结合AZ CLI创建PostgreSQL输出时,返回以下错误:

(BadRequest) The JSON provided in the request body is invalid. The required property 'datasource type' is missing from the request.
Code: BadRequest

替换数据源类型为Azure SQL的Microsoft.Sql/Server/Database时命令可正常执行,且通过Azure门户、Terraform可以成功创建PostgreSQL输出。

原因分析

AZ CLI的az stream-analytics output create命令对不同输出类型的type字段存在参数约定差异:

  • Azure SQL输出使用ARM资源类型Microsoft.Sql/Server/Database符合命令预期;
  • PostgreSQL输出需要使用简化类型标识PostgreSQL,而非ARM资源类型Microsoft.DBforPostgreSQL/servers/databases。原JSON中的类型不被命令识别,因此触发"缺少数据源类型"的错误。
  • 门户和Terraform直接调用ARM API时,使用了正确的参数映射或ARM资源类型,因此可以成功创建输出。

解决方案

修改数据源JSON中的type字段为PostgreSQL,保持properties字段结构不变,重新生成转义后的JSON字符串执行命令即可。

修正后的PowerShell代码

$dataSourceJson = @"
{
    "type": "PostgreSQL",
    "properties": {
        "server": "<YourHostFullName>",
        "database": "<YourDbName>",
        "table": "<YourTableName>",
        "user": "<user>",
        "password": "<password>"
    }
}
"@

# 输出验证内容
Write-Host "Datasource JSON String:"
Write-Host $dataSourceJson

# 处理JSON为单行、转义双引号
$dataSource = ($dataSourceJson -replace "\s+", "") -replace '"', '\"'

Write-Host "处理后的Datasource JSON:"
Write-Host $dataSource

# 创建输出
az stream-analytics output create `
    --job-name "<YourJobName>" `
    --name "<YourOutputName>" `
    --resource-group "<YourResourceGroupName>" `
    --datasource "$dataSource" `
    --verbose

补充说明

执行成功后,使用az stream-analytics output show查看输出详情时,数据源类型可能仍显示为Microsoft.DBforPostgreSQL/servers/databases,这是因为AZ CLI底层将简化类型PostgreSQL映射为了对应的ARM资源类型,属于正常现象。

内容的提问来源于stack exchange,提问作者Francois Denis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 17:30:08