[英]Using Event Grid, is it possible to trigger a logic app when a resource is created/deleted in Azure?
我想知道如果使用事件网格,是否可以在 Azure 订阅上部署任何资源时触发逻辑应用程序。
用例是:
此处的目标是对这艘潜艇上发生的事情有一个简单和基本的直升机视图。
出于测试目的,我创建了一个逻辑应用程序并使用Microsoft.Resources.ResourceGroups和这些事件类型添加了“当资源事件发生时”触发器:
Microsoft.Resources.ResourceActionSuccess
Microsoft.Resources.ResourceDeleteSuccess
Microsoft.Resources.ResourceWriteSuccess
不确定我在这里探索。
然后我部署了一个storageaccount ,但即使在实际部署资源之前“查看”部署时我也会收到通知。
部署后,我还会收到随机通知(即使未使用存储帐户,我猜是某种后台活动?)
根据此官方文档:
为发送到
management.azure.com
的 PUT、PATCH、POST 和 DELETE 操作创建资源事件。 GET 操作不会创建事件。
因此,您收到多个触发器。 对于最少的触发器,您可以为部署添加过滤器。 以下是我正在使用的流程。
以下是我的逻辑应用程序的完整 JSON
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Send_an_email_(V2)": {
"inputs": {
"body": {
"Body": "<p>@{triggerBody()?['subject']} has been created</p>",
"Importance": "Normal",
"Subject": "xxx",
"To": "xxx"
},
"host": {
"connection": {
"name": "@parameters('$connections')['office365']['connectionId']"
}
},
"method": "post",
"path": "/v2/Mail"
},
"runAfter": {},
"type": "ApiConnection"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"When_a_resource_event_occurs": {
"conditions": [],
"inputs": {
"body": {
"properties": {
"destination": {
"endpointType": "webhook",
"properties": {
"endpointUrl": "@{listCallbackUrl()}"
}
},
"filter": {
"includedEventTypes": [
"Microsoft.Resources.ResourceDeleteSuccess",
"Microsoft.Resources.ResourceActionSuccess"
],
"subjectBeginsWith": "/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Resources/deployments"
},
"topic": "/subscriptions/xxx/resourceGroups/xxx"
}
},
"host": {
"connection": {
"name": "@parameters('$connections')['azureeventgrid']['connectionId']"
}
},
"path": "/subscriptions/@{encodeURIComponent('b83c1ed3-c5b6-44fb-b5ba-2b83a074c23f')}/providers/@{encodeURIComponent('Microsoft.Resources.ResourceGroups')}/resource/eventSubscriptions",
"queries": {
"x-ms-api-version": "2017-09-15-preview"
}
},
"splitOn": "@triggerBody()",
"type": "ApiConnectionWebhook"
}
}
},
"parameters": {
"$connections": {
"value": {
"azureeventgrid": {
"connectionId": "/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Web/connections/azureeventgrid",
"connectionName": "azureeventgrid",
"id": "/subscriptions/xxx/providers/Microsoft.Web/locations/eastus/managedApis/azureeventgrid"
},
"office365": {
"connectionId": "/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Web/connections/office365",
"connectionName": "office365",
"id": "/subscriptions/xxx/providers/Microsoft.Web/locations/eastus/managedApis/office365"
}
}
}
}
}
结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.