用输出覆盖Azure Function Table Store行



我有一个Azure PowerShell函数,它查询API管理分析以获取API的列表,然后通过函数集成输出到表存储表

为每个API创建一行,PartitionKey是API的名称,

RowKey如果API的分析每天被请求不止一次,这将导致错误。此时,功能执行失败,状态为500内部服务器错误,我将看到以下错误-

函数返回后处理参数_binder时出错:->指定的实体已存在。

虽然我计划按计划运行函数,从而在大多数时候避免这个问题,但最好有一个解决方案,理想的情况是覆盖现有条目。这可能吗?

$apiIds.GetEnumerator() | ForEach-Object {
$analytic = $_.Value | Get-ApiManagementAnalytics -Context $context -StartDate $startDate -EndDate $endDate -AccessToken
$tableRow = $analytic.value
$tableRow | Add-Member -NotePropertyName PartitionKey -NotePropertyValue $tableRow.name
$tableRow | Add-Member -NotePropertyName RowKey -NotePropertyValue ((Get-Date).ToString("yyyy-MM-dd"))
$tableRows += $tableRow
}
$tableRows | ConvertTo-Json | Out-File -Encoding UTF8 $outputTable

我相信您正在寻找的是TableOperation.InsertOrReplace

如果实体不存在,则将给定实体插入表中;如果实体确实存在,则其内容将替换为所提供的实体。

请参阅:https://stackoverflow.com/a/55527201

public string ETag { get; } = "*";

最新更新