訓練
認證
Microsoft Certified: Azure Developer Associate - Certifications
在 Microsoft Azure 中建置端對端解決方案,以建立 Azure Functions、實作和管理 Web 應用程式、開發使用 Azure 儲存體的解決方案等等。
Azure 快速入門範本是社群參與的範本存放庫。 您可以在範本開發中使用範例範本。 在本教學課程中,您會尋找網站資源定義,然後將其新增至自己的範本。 完成此指示需要 12 分鐘的時間。
我們建議您完成有關匯出範本的教學課程,但並非必要。
您必須具有 Visual Studio Code 並搭配 Resource Manager 工具延伸模組,以及 Azure PowerShell 或 Azure 命令列介面 (CLI)。 如需詳細資訊,請參閱範本工具。
在上一個教學課程結束時,您的範本會具有下列 JSON 檔案:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storagePrefix": {
"type": "string",
"minLength": 3,
"maxLength": 11
},
"storageSKU": {
"type": "string",
"defaultValue": "Standard_LRS",
"allowedValues": [
"Standard_LRS",
"Standard_GRS",
"Standard_RAGRS",
"Standard_ZRS",
"Premium_LRS",
"Premium_ZRS",
"Standard_GZRS",
"Standard_RAGZRS"
]
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]"
},
"appServicePlanName": {
"type": "string",
"defaultValue": "exampleplan"
}
},
"variables": {
"uniqueStorageName": "[concat(parameters('storagePrefix'), uniqueString(resourceGroup().id))]"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2021-09-01",
"name": "[variables('uniqueStorageName')]",
"location": "[parameters('location')]",
"sku": {
"name": "[parameters('storageSKU')]"
},
"kind": "StorageV2",
"properties": {
"supportsHttpsTrafficOnly": true
}
},
{
"type": "Microsoft.Web/serverfarms",
"apiVersion": "2021-03-01",
"name": "[parameters('appServicePlanName')]",
"location": "[parameters('location')]",
"sku": {
"name": "B1",
"tier": "Basic",
"size": "B1",
"family": "B",
"capacity": 1
},
"kind": "linux",
"properties": {
"perSiteScaling": false,
"reserved": true,
"targetWorkerCount": 0,
"targetWorkerSizeId": 0
}
}
],
"outputs": {
"storageEndpoint": {
"type": "object",
"value": "[reference(variables('uniqueStorageName')).primaryEndpoints]"
}
}
}
此範本適用於部署儲存體帳戶和 App Service 方案,但您可能想要在其中新增網站。 您可以使用預先建置的範本,快速探索部署資源所需的 JSON。
開啟 Azure 快速入門範本
選取標題為部署基本 Linux Web 應用程式的圖格。 如果您找不到該範本,以下為直接連結。
選取 [在 GitHub 上瀏覽]。
選取 [azuredeploy.json]。
檢閱範本。 尋找 Microsoft.Web/sites
資源。
將快速入門範本與現有範本合併:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storagePrefix": {
"type": "string",
"minLength": 3,
"maxLength": 11
},
"storageSKU": {
"type": "string",
"defaultValue": "Standard_LRS",
"allowedValues": [
"Standard_LRS",
"Standard_GRS",
"Standard_RAGRS",
"Standard_ZRS",
"Premium_LRS",
"Premium_ZRS",
"Standard_GZRS",
"Standard_RAGZRS"
]
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]"
},
"appServicePlanName": {
"type": "string",
"defaultValue": "exampleplan"
},
"webAppName": {
"type": "string",
"metadata": {
"description": "Base name of the resource such as web app name and app service plan "
},
"minLength": 2
},
"linuxFxVersion": {
"type": "string",
"defaultValue": "php|7.0",
"metadata": {
"description": "The Runtime stack of current web app"
}
}
},
"variables": {
"uniqueStorageName": "[concat(parameters('storagePrefix'), uniqueString(resourceGroup().id))]",
"webAppPortalName": "[concat(parameters('webAppName'), uniqueString(resourceGroup().id))]"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2021-09-01",
"name": "[variables('uniqueStorageName')]",
"location": "[parameters('location')]",
"sku": {
"name": "[parameters('storageSKU')]"
},
"kind": "StorageV2",
"properties": {
"supportsHttpsTrafficOnly": true
}
},
{
"type": "Microsoft.Web/serverfarms",
"apiVersion": "2021-03-01",
"name": "[parameters('appServicePlanName')]",
"location": "[parameters('location')]",
"sku": {
"name": "B1",
"tier": "Basic",
"size": "B1",
"family": "B",
"capacity": 1
},
"kind": "linux",
"properties": {
"perSiteScaling": false,
"reserved": true,
"targetWorkerCount": 0,
"targetWorkerSizeId": 0
}
},
{
"type": "Microsoft.Web/sites",
"apiVersion": "2021-03-01",
"name": "[variables('webAppPortalName')]",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName'))]"
],
"kind": "app",
"properties": {
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName'))]",
"siteConfig": {
"linuxFxVersion": "[parameters('linuxFxVersion')]"
}
}
}
],
"outputs": {
"storageEndpoint": {
"type": "object",
"value": "[reference(variables('uniqueStorageName')).primaryEndpoints]"
}
}
}
Web 應用程式名稱在 Azure 上必須是唯一的。 為避免名稱重複,已將 webAppPortalName
變數從 "webAppPortalName": "[concat(parameters('webAppName'), '-webapp')]"
更新為 "webAppPortalName": "[concat(parameters('webAppName'), uniqueString(resourceGroup().id))]"
。
在 Microsoft.Web/serverfarms
定義的結尾新增逗號,以將資源定義與 Microsoft.Web/sites
定義分開。
在此新資源中,有數個需注意的重要功能。
其有一個名為 dependsOn
且已設為 App Service 方案的元素。 這是必要設定,因為 App Service 方案必須存在,才能建立 Web 應用程式。 dependsOn
元素會告訴 Resource Manager 如何排序要部署的資源。
serverFarmId
屬性會使用 resourceId 函式。 此函式會取得資源的唯一識別碼。 在此案例中,它會取得 App Service 方案的唯一識別碼。 Web 應用程式會與一個特定的 App Service 方案相關聯。
使用 Azure CLI 或 Azure PowerShell 來部署範本。
如果您尚未建立資源群組,請參閱建立資源群組。 此範例假設您已將 templateFile 變數設為範本檔案的路徑,如第一個教學課程所示。
New-AzResourceGroupDeployment `
-Name addwebapp `
-ResourceGroupName myResourceGroup `
-TemplateFile $templateFile `
-storagePrefix "store" `
-storageSKU Standard_LRS `
-webAppName demoapp
注意
如果部署失敗,請使用 verbose
參數來取得所建立資源的相關資訊。 使用 debug
參數來取得更多資訊以進行偵錯。
如果您要繼續進行下一個教學課程,則不需要刪除資源群組。
如果您現在要停止,則可能想要刪除資源群組。
您已了解如何使用快速入門範本進行範本開發。 在下一個教學課程中,您會將標記新增至資源。
訓練
認證
Microsoft Certified: Azure Developer Associate - Certifications
在 Microsoft Azure 中建置端對端解決方案,以建立 Azure Functions、實作和管理 Web 應用程式、開發使用 Azure 儲存體的解決方案等等。
文件
教學課程 - 建立及部署範本 - Azure Resource Manager
建立第一個 Azure Resource Manager 範本 (ARM 範本)。 在本教學課程中,您將了解範本檔案語法及部署儲存體帳戶的方式。
使用範本參考 - Azure Resource Manager
使用 Azure Resource Manager 範本 (ARM 範本) 參考來建立範本。
建立範本 - Visual Studio Code - Azure Resource Manager
利用 Visual Studio Code 和 Azure Resource Manager Tools 擴充功能來使用 Azure Resource Manager 範本 (ARM 範本)。