如何更新Azure数据工厂链接服务中使用的Cosmos DB帐户密钥

问题描述

我正在尝试通过PowerShell更新Data Factory V2链接服务,但无法获得有效的定义文件

我的情况是,旋转了Cosmos DB帐户密钥后,应该使用新密钥更新连接到该帐户上的数据库的Data Factory链接服务。为此,我要从链接服务中提取现有属性,更新EncryptedCredentialAdditionalProperties.typeProperties.encryptedCredential属性,然后将其重新触发。

$deFinitionFile = "{0}/cosmosDbDeFinition.json" -f $PSScriptRoot
$deFinition = (Get-AzDataFactoryV2LinkedService -Name $LinkedServiceName -DataFactoryName $Name -ResourceGroupName $ResourceGroupName).Properties
$deFinition.EncryptedCredential = ConvertTo-securestring -String $key -AsPlainText
Set-Content -Path $deFinitionFile -Value ($deFinition | ConvertTo-Json)
Set-AzDataFactoryV2LinkedService -Name $Name -DataFactoryName $DataFactoryName -ResourceGroupName $ResourceGroupName -DeFinitionFile $deFinitionFile -Force

但是,由于Set-AzDataFactoryV2LinkedService失败,我显然做错了-

无效的链接服务有效负载,有效负载中嵌套的'typeProperties'为空。

根据错误typeProperties在有效负载中不为null。但是,我不确定简单地将属性重新触发是正确的做法。

documentation不包含任何示例定义文件,并且我找不到任何有效的示例(也许我在搜索错误的东西)。

如何正确更新Cosmos DB的数据工厂链接服务的密钥?

解决方法

Azure数据工厂链接服务的定义文件应如下所示。有关更多详细信息,请参阅herehere

{
    "name": "<Name of the linked service>","properties": {
        "type": "<Type of the linked service>","typeProperties": {
              "<data store or compute-specific type properties>"
        },"connectVia": {
            "referenceName": "<name of Integration Runtime>","type": "IntegrationRuntimeReference"
        }
    }
}

如果要更新Azure CosmosDB帐户密钥,请参考以下脚本

$key="<account key>"
$definition = (Get-AzDataFactoryV2LinkedService -Name $LinkedServiceName -DataFactoryName $Name -ResourceGroupName $ResourceGroupName).Properties
$newdef=@{
  "properties" =@{
    "type"="CosmosDb"
    "typeProperties"= @{
      "connectionString"= $definition.ConnectionString+ "AccountKey=$($key)"
     
    }
  
  }
} | ConvertTo-Json -Depth 10

$newdef | Out-File E:\test.json

Set-AzDataFactoryV2LinkedService -Name $LinkedServiceName -DataFactoryName $Name -ResourceGroupName $ResourceGroupName -DefinitionFile E:\test.json
 

enter image description here