在 Azure 函数绑定中访问 EventGridEvent.EventType
Accessing EventGridEvent.EventType in Azure function binding
我有一个由 EventGridEvent
触发的 Azure 函数。我正在尝试将所有事件存储在 Azure table 中,并为每个 table 事件命名。
这就是我不绑定的解决方法:
[FunctionName("MyFunction")]
public static async Task MyFunction([EventGridTrigger] EventGridEvent eventGridEvent)
{
var table = CloudStorageAccount.Parse(Environment.GetEnvironmentVariable("AzureWebJobsStorage")).CreateCloudTableClient().GetTableReference(eventGridEvent.EventType);
await table.CreateIfNotExistsAsync();
// etc...
}
但我想用绑定来完成它。
这是我试过的:
[FunctionName("MyFunction")]
public static async Task MyFunction(
[EventGridTrigger] EventGridEvent eventGridEvent,
[Table("{EventType}")] CloudTable table)
{
}
我收到这个错误:
Microsoft.Azure.WebJobs.Host: Error indexing method 'MyFunction'. Microsoft.Azure.WebJobs.Host: Unable to resolve binding parameter 'EventType'. Binding expressions must map to either a value provided by the trigger or a property of the value the trigger is bound to, or must be a system binding expression (e.g. sys.randguid, sys.utcnow, etc.).
肯定 EventType
是 EventGridEvent
的 属性 触发器绑定的吗?
我应该如何在绑定中访问 EventGridEvent.EventType
?
不幸的是,对于事件网格 trigger/binding,不支持那种 属性 绑定表达式(例如 {EventType}
)。这就是为什么您在 Event Grid trigger doc as opposed to places where such binding is supported (e.g. Service Bus)
中看不到它的原因
我有一个由 EventGridEvent
触发的 Azure 函数。我正在尝试将所有事件存储在 Azure table 中,并为每个 table 事件命名。
这就是我不绑定的解决方法:
[FunctionName("MyFunction")]
public static async Task MyFunction([EventGridTrigger] EventGridEvent eventGridEvent)
{
var table = CloudStorageAccount.Parse(Environment.GetEnvironmentVariable("AzureWebJobsStorage")).CreateCloudTableClient().GetTableReference(eventGridEvent.EventType);
await table.CreateIfNotExistsAsync();
// etc...
}
但我想用绑定来完成它。
这是我试过的:
[FunctionName("MyFunction")]
public static async Task MyFunction(
[EventGridTrigger] EventGridEvent eventGridEvent,
[Table("{EventType}")] CloudTable table)
{
}
我收到这个错误:
Microsoft.Azure.WebJobs.Host: Error indexing method 'MyFunction'. Microsoft.Azure.WebJobs.Host: Unable to resolve binding parameter 'EventType'. Binding expressions must map to either a value provided by the trigger or a property of the value the trigger is bound to, or must be a system binding expression (e.g. sys.randguid, sys.utcnow, etc.).
肯定 EventType
是 EventGridEvent
的 属性 触发器绑定的吗?
我应该如何在绑定中访问 EventGridEvent.EventType
?
不幸的是,对于事件网格 trigger/binding,不支持那种 属性 绑定表达式(例如 {EventType}
)。这就是为什么您在 Event Grid trigger doc as opposed to places where such binding is supported (e.g. Service Bus)