在 Azure 存储帐户中创建 Table

Create Table in Azure Storage Account

有没有办法使用 ARM 模板在 Azure 存储帐户中创建 Table?我可以使用 PowerShell 实现这一点,但找不到使用 JSON 模板的方法,而且当我使用 (https://resources.azure.com) 浏览我的部署资源时,我看不到对创建的 table 在存储帐户下,知道为什么吗?

谢谢, 一个赛亚姆

  1. 据我所知,没有。您可以查看 Get started with Azure Table storage using .NET/PHP/Python/... 了解详细信息。
  2. Table 服务通过 REST API 公开帐户、Tables、实体,因此您无法在门户中看到它们。您可以查看 Addressing Table Service Resources 了解更多信息。

通过一些简单的步骤使用 ARM 模板创建 Azure 存储。请找到以下步骤来实现它。

第 1 步:打开您的 powershell 并使用 Connect-AzureRmAccount

登录您的帐户

第 2 步:添加您的 SubscriptionId Select-AzureRmSubscription -SubscriptionId <your SubscriptionId>

第 3 步:创建资源组 New-AzureRmResourceGroup -Name yourResourceGroup -Location "South Central US"

第 4 步:创建 azuredeploy.json 和 azuredeploy.parameters.json

azuredeploy.json

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
    "storageAccountName": {
        "type": "string",
        "metadata": {
            "description": "The name of the Azure Storage account."
        }
    },
    "containerName": {
        "type": "string",
        "defaultValue": "logs",
        "metadata": {
            "description": "The name of the blob container."
        }
    },
    "location": {
        "type": "string",
        "defaultValue": "[resourceGroup().location]",
        "metadata": {
            "description": "The location in which the Azure Storage resources should be deployed."
        }
    }
},
"resources": [
    {
        "name": "[parameters('storageAccountName')]",
        "type": "Microsoft.Storage/storageAccounts",
        "apiVersion": "2018-02-01",
        "location": "[parameters('location')]",
        "kind": "StorageV2",
        "sku": {
            "name": "Standard_LRS",
            "tier": "Standard"
        },
        "properties": {
            "accessTier": "Hot"
        },
        "resources": [
            {
                "name": "[concat('default/', parameters('containerName'))]",
                "type": "blobServices/containers",
                "apiVersion": "2018-03-01-preview",
                "dependsOn": [
                    "[parameters('storageAccountName')]"
                ]
            }
        ]
    }
]
}

azuredeploy.parameters.json

{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
    "storageAccountName": {
        "value": "yourstorage"
    }
}
}

第 5 步:运行以下命令

New-AzureRmResourceGroupDeployment -Name myDeployment -ResourceGroupName yourResourceGroup -TemplateFile <location>\azuredeploy.json -TemplateParameterFile <location>\azuredeploy.parameters.json

第 6 步:

$saContext = (Get-AzureRmStorageAccount -ResourceGroupName yourResourceGroup -Name sitastoragee).Context 
New-AzureStorageTable –Name yourtablestorage –Context $saContext

您可以像这样通过 ARM 使用 table 创建 Azure 存储帐户,使用 storageAccount 资源上的 tableServices/tables 子资源:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "storageAccountName": {
      "type": "string",
      "minLength": 3,
      "maxLength": 24
    },
    "storageAccountSku": {
      "type": "string",
      "defaultValue": "Standard_LRS",
      "allowedValues": [
        "Standard_LRS",
        "Standard_GRS",
        "Standard_RAGRS"
      ]
    },
    "tableName": {
      "type": "string",
      "minLength": 3,
      "maxLength": 63
    }
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "name": "[parameters('storageAccountName')]",
      "apiVersion": "2019-06-01",
      "location": "[resourceGroup().location]",
      "kind": "StorageV2",
      "sku": {
        "name": "[parameters('storageAccountSku')]"
      },
      "resources": [
        {
          "name": "[concat('default/', parameters('tableName'))]",
          "type": "tableServices/tables",
          "apiVersion": "2019-06-01",
          "dependsOn": [
            "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]"
          ]
        }
      ]
    }
  ]
}

该功能记录在 ARM Template spec page for tableServices/tables