【问题标题】:Unable to set EventGrid Subscription Advanced Filter in Azure CLI using a Variable无法使用变量在 Azure CLI 中设置 EventGrid 订阅高级筛选器
【发布时间】:2020-04-08 14:33:50
【问题描述】:

我正在尝试在 Azure DevOps 中创建一个动态的 Azure CLI 任务,以便我们重用该任务。我现在最大的问题是在命令上动态设置 --advanced-filter。

我查看了此处的文档 https://docs.microsoft.com/en-us/azure/event-grid/how-to-filter-events,它使用过滤器变量显示的唯一位置是 PowerShell 命令而不是 Azure CLI。我试图为 CLI 复制该语法,但它失败了。

这是我要运行的命令。我从上面的 Microsoft 文档中获取了过滤器的语法。

$eventSubscriptionFilter = @{operator="StringContains"; key="data.messageTypeUri"; Value=@("myUriHere")}

az eventgrid event-subscription create --endpoint-type azurefunction --name $topicSubName --source-resource-id $topicid --endpoint $functionEndPoint --deadletter-endpoint $storageid/blobServices/default/containers/$containername --advanced-filter @($eventSubscriptionFilter)

如果我在没有 --advanced-filter 的情况下运行它,它会完美运行,但是一旦我添加 --advanced-filter 我就会收到此错误:

az : usage error: --advanced-filter KEY[.INNERKEY] FILTEROPERATOR VALUE [VALUE ...]

这是我必须要做的吗?

--advanced-filter data.$myMember StringContains $myValue

我什至不确定这是否会奏效。我将不得不在那里对其进行硬编码,这会扼杀使这种动态的能力。

有什么想法吗?

【问题讨论】:

    标签: azure azure-cli azure-eventgrid


    【解决方案1】:

    如果你想在 Azure CLI 命令中指定--advanced-filter,它应该像--advanced-filter [key] [operation] [value]。更多详情请参考document

    例如(我在Powershell中测试过)

    $key="data.Message"
    $opreation="StringContains"
    $value=@("test","test1")
    az eventgrid event-subscription create 
     --name $topicSubName 
     --source-resource-id $topicid 
     --endpoint $functionEndPoint 
     --deadletter-endpoint $storageid/blobServices/default/containers/$containername 
     --advanced-filter $key $opreation $value
    

    【讨论】:

    • 这行得通,谢谢。它抛出的错误让我陷入了循环。不确定它是否期待不同的东西。
    • 您好,很抱歉插手,但您能否解释一下如何在 ARM 模板中设置 advancedFilter 值?我已经这样设置了"advancedFilters": [ { "key": "subject", "operatorType": "StringContains", "value": "inputs" } ],并且设置了键和运算符,但没有设置值。
    猜你喜欢
    • 2021-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-25
    • 2021-01-09
    • 2021-08-16
    相关资源
    最近更新 更多