使用ARM模板创建Azure存储队列

问题描述 投票:8回答:3

是否可以通过ARM模板创建Azure存储队列?我可以找到一种创建容器的方法,但是找不到与通过ARM创建存储队列有关的任何内容。

azure azure-storage azure-resource-manager arm-template
3个回答
4
投票

[不,您无法通过ARM模板创建Azure存储队列,但我怀疑是否有必要,因为使用e。 G。 .NET SDK与队列交互,您可以调用CreateIfNotExistsAsync()方法来创建它。示例:

// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
    CloudConfigurationManager.GetSetting("StorageConnectionString"));

// Create the queue client.
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();

// Retrieve a reference to a container.
CloudQueue queue = queueClient.GetQueueReference("myqueue");

// Create the queue async if it doesn't already exist
await queue.CreateIfNotExistsAsync();

Source


1
投票

ARM目前不支持创建存储队列(截至2020-01)。 2018-02-01 version of the API中已添加了容器支持。在2019-04-01中,已添加文件共享。

应该通过SDK调用在应用程序启动代码中创建队列,或者在通过Azure CLIaz storage queue create)进行部署时甚至更好。

您可以在Azure DevOps中添加Azure CLI任务,连接订阅并为其提供内联脚本,如下所示:

az storage queue create

如果使用的是Windows构建代理,则需要包括call az storage queue create -n "awesome-queue-1" --connection-string "$(storageAccountConnectionString)" 以确保执行多行。如果您使用的是Linux代理,则可以省略call

该连接字符串可以从ARM模板作为输出参数导出,然后使用call吸收到DevOps变量中。

-ARM Outputs

也有Simon Timms: Creating Storage Queues in Azure DevOps @ Western Devs用于在部署ARM模板期间执行代码。


0
投票

不,目前无法执行此操作。容器是最近才添加的。

您始终可以使用Azure Function hack:只需将该函数作为嵌套部署进行调用,并对该函数进行编码即可完成所有工作。

或者您可以使用other options,它将正在运行的脚本作为ARM模板部署的一部分。 (当前处于预览状态,您需要预订预览。)

© www.soinside.com 2019 - 2024. All rights reserved.