在 Azure 门户中从我的 Azure 存储帐户创建“删除旧 blob”自动化任务后,我获得了 2 个资源:一个 LogicApp 和一个自动称为“azureblob-MyStorageName”的 API 连接。
我导出了LogicApp的ARM模板,重新从头创建了LogicApp。但部署失败。
ARM模板到此结束:
"parameters": {
"$connections": {
"value": {
"azureblob": {
"id": "/subscriptions/xxx-xxx-xxx-xxx/providers/Microsoft.Web/locations/francecentral/managedApis/azureblob",
"connectionName": "azureblob-mystorageaccountname",
"connectionId": "[resourceId('Microsoft.Web/connections', 'azureblob-mystorageaccountname')]"
}
}
}
}
我收到此错误:
Error:The managedBy resource id is missing in workflow 'CleanBlob-Daily'. ManagedBy must be provided if resource kind is 'AutomationTask'. Click here for details
在这篇 Microsoft 文章 Microsoft.Weblocations/managedApis 中,它说使用引用来创建 Api 连接,但由于处于只读状态而无法部署。
不过这端的ARM模板使用参考:
"parameters": {
"$connections": {
"value": {
"azureblob": {
"id": "[reference(resourceId('Microsoft.Web/locations/managedApis', '{azureblob}'), '2016-06-01')]",
"connectionName": "[parameters('apiConnectionName')]",
"connectionId": "[resourceId('Microsoft.Web/connections', 'azureblob-kpmgfrsasbxdocs0002')]"
}
}
}
}
我收到此错误:
Deployment template validation failed: 'The template resource 'CleanBlob-Daily' at line '1' and column '1335' is not valid: Unable to evaluate template language function 'resourceId': the type 'Microsoft.Web/locations/managedApis' requires '2' resource name argument(s). Please see https://aka.ms/arm-resource-functions/#resourceid for usage details.. Please see https://aka.ms/arm-functions for usage details.'. (Code: InvalidTemplate)
那么,如何使用 ARM 创建“删除旧 blob”自动化任务?
我使用从 Delete old blobs 自动化任务生成的代码创建了一个新的逻辑应用程序,并对其进行了一些修改。我正在使用 ARM 模板部署它。
代码-
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.Logic/workflows",
"apiVersion": "2016-06-01",
"name": "{LogicApp_Name}",
"location": "eastus",
"properties": {
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"For_each": {
"actions": {
"Condition": {
"actions": {
"Delete_blob": {
"description": "If blob is older than the expiration age, delete it",
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['azureblob']['connectionId']"
}
},
"method": "delete",
"path": "/datasets/default/files/@{encodeURIComponent(encodeURIComponent(items('For_each')?['Id']))}"
},
"runAfter": {},
"type": "ApiConnection"
}
},
"description": "Check LastModified timestamp and whether older than the expiration age variable",
"expression": "@less(ticks(items('For_each')?['LastModified']), ticks(addDays(utcnow(), if(equals(parameters('Time'),'Days'), variables('ExpirationAgeInDays'), if(equals(parameters('Time'), 'Weeks'), mul(variables('ExpirationAgeInDays'), 7), if(equals(parameters('Time'),'Months'), mul(variables('ExpirationAgeInDays'), 30), variables('ExpirationAgeInDays')))))))",
"runAfter": {},
"type": "If"
}
},
"description": "Scan all blobs in this folder",
"foreach": "@body('List_blobs')?['value']",
"runAfter": {
"List_blobs": [
"Succeeded"
]
},
"type": "Foreach"
},
"List_blobs": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['azureblob']['connectionId']"
}
},
"method": "get",
"path": "/datasets/default/foldersV2/@{encodeURIComponent(encodeURIComponent(parameters('BlobFolder')))}",
"queries": {
"useFlatListing": true
}
},
"runAfter": {
"Set_expiration_age_variable_": [
"Succeeded"
]
},
"runtimeConfiguration": {
"paginationPolicy": {
"minimumItemCount": 5000
}
},
"type": "ApiConnection"
},
"Set_expiration_age_variable_": {
"description": "A variable to configure the auto expiration age in days. Default is 30 (30 days old).",
"inputs": {
"variables": [
{
"name": "ExpirationAgeInDays",
"type": "integer",
"value": "@if(greater(parameters('ExpirationAge'), 0), mul(parameters('ExpirationAge'), -1), parameters('ExpirationAge'))"
}
]
},
"runAfter": {},
"type": "InitializeVariable"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
},
"BlobFolder": {
"defaultValue": "demo",
"metadata": {
"displayName": "Blob container name",
"isLinkedResource": false,
"placeholder": "",
"required": true
},
"type": "String"
},
"ExpirationAge": {
"defaultValue": 10,
"metadata": {
"description": "Blobs older than this age will be deleted",
"displayName": "Expiration age",
"isLinkedResource": false,
"required": true
},
"type": "Int"
},
"Time": {
"allowedValues": [
"Days",
"Weeks",
"Months"
],
"defaultValue": "Days",
"metadata": {
"allowedValues": [
"Days",
"Weeks",
"Months"
],
"displayName": "Time Unit",
"isLinkedResource": false,
"placeholder": "Days",
"required": true
},
"type": "String"
}
},
"triggers": {
"Recurrence": {
"evaluatedRecurrence": {
"frequency": "Day",
"interval": 1
},
"recurrence": {
"frequency": "Day",
"interval": 1
},
"type": "Recurrence"
}
}
},
"parameters": {
"$connections": {
"value": {
"azureblob": {
"connectionId": "/subscriptions/{Subscription_Id}/resourceGroups/{Resourcegroup_name}/providers/Microsoft.Web/connections/azureblob-afrinstore01",
"connectionName": "azureblob-afrinstore01",
"id": "/subscriptions/{Subscription_Id}/providers/Microsoft.Web/locations/eastus/managedApis/azureblob"
}
}
}
}
}
}
]
}
请添加您的连接参数。我已使用
az deployment group create --resource-group <resourceGroup_Name> --template-file <ARM_File_Name.json>
命令进行部署。
我已经取得了成功的结果。