title | description | services | author | ms.service | ms.topic | ms.date | ms.author | ms.custom |
---|---|---|---|---|---|---|---|---|
Provision Web App with Azure Cache for Redis |
Use Azure Resource Manager template to deploy web app with Azure Cache for Redis. |
app-service |
flang-msft |
app-service |
conceptual |
01/06/2017 |
franlanglois |
devx-track-azurepowershell |
[!INCLUDE updated-for-az]
In this article, you learn how to create an Azure Resource Manager template that deploys an Azure Web App with Azure Cache for Redis. You'll learn the following deployment details:
- How to define which resources are deployed
- How to define parameters that are specified when the deployment is executed
You can use this template for your own deployments, or customize it to meet your requirements.
For more information about creating templates, see Authoring Azure Resource Manager templates. To learn about the JSON syntax and properties for cache resource types, see Microsoft.Cache resource types.
For the complete template, see Web App with Azure Cache for Redis template.
In this template, you deploy:
- Azure Web App
- Azure Cache for Redis
To run the deployment automatically, select the following button:
[!INCLUDE app-service-web-deploy-web-parameters]
[!INCLUDE cache-deploy-parameters]
This template uses variables to construct names for the resources. It uses the uniqueString function to construct a value based on the resource group id.
"variables": {
"hostingPlanName": "[concat('hostingplan', uniqueString(resourceGroup().id))]",
"webSiteName": "[concat('webSite', uniqueString(resourceGroup().id))]",
"cacheName": "[concat('cache', uniqueString(resourceGroup().id))]"
},
[!INCLUDE app-service-web-deploy-web-host]
Creates the Azure Cache for Redis that is used with the web app. The name of the cache is specified in the cacheName variable.
The template creates the cache in the same location as the resource group.
{
"name": "[variables('cacheName')]",
"type": "Microsoft.Cache/Redis",
"location": "[resourceGroup().location]",
"apiVersion": "2015-08-01",
"dependsOn": [ ],
"tags": {
"displayName": "cache"
},
"properties": {
"sku": {
"name": "[parameters('cacheSKUName')]",
"family": "[parameters('cacheSKUFamily')]",
"capacity": "[parameters('cacheSKUCapacity')]"
}
}
}
Creates the web app with name specified in the webSiteName variable.
Notice that the web app is configured with app setting properties that enable it to work with the Azure Cache for Redis. These app settings are dynamically created based on values provided during deployment.
{
"apiVersion": "2015-08-01",
"name": "[variables('webSiteName')]",
"type": "Microsoft.Web/sites",
"location": "[resourceGroup().location]",
"dependsOn": [
"[concat('Microsoft.Web/serverFarms/', variables('hostingPlanName'))]"
],
"tags": {
"[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', variables('hostingPlanName'))]": "empty",
"displayName": "Website"
},
"properties": {
"name": "[variables('webSiteName')]",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]"
},
"resources": [
{
"apiVersion": "2015-08-01",
"type": "config",
"name": "appsettings",
"dependsOn": [
"[concat('Microsoft.Web/Sites/', variables('webSiteName'))]",
"[concat('Microsoft.Cache/Redis/', variables('cacheName'))]"
],
"properties": {
"CacheConnection": "[concat(variables('cacheHostName'),'.redis.cache.windows.net,abortConnect=false,ssl=true,password=', listKeys(resourceId('Microsoft.Cache/Redis', variables('cacheName')), '2015-08-01').primaryKey)]"
}
}
]
}
For RedisEnterprise, because the resource types are slightly different, the way to do listKeys is different:
{
"apiVersion": "2015-08-01",
"name": "[variables('webSiteName')]",
"type": "Microsoft.Web/sites",
"location": "[resourceGroup().location]",
"dependsOn": [
"[concat('Microsoft.Web/serverFarms/', variables('hostingPlanName'))]"
],
"tags": {
"[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', variables('hostingPlanName'))]": "empty",
"displayName": "Website"
},
"properties": {
"name": "[variables('webSiteName')]",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]"
},
"resources": [
{
"apiVersion": "2015-08-01",
"type": "config",
"name": "appsettings",
"dependsOn": [
"[concat('Microsoft.Web/Sites/', variables('webSiteName'))]",
"[concat('Microsoft.Cache/RedisEnterprise/databases/', variables('cacheName'), "/default")]",
],
"properties": {
"CacheConnection": "[concat(variables('cacheHostName'),abortConnect=false,ssl=true,password=', listKeys(resourceId('Microsoft.Cache/RedisEnterprise', variables('cacheName'), 'default'), '2020-03-01').primaryKey)]"
}
}
]
}
[!INCLUDE app-service-deploy-commands]
New-AzResourceGroupDeployment -TemplateUri https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.web/web-app-with-redis-cache/azuredeploy.json -ResourceGroupName ExampleDeployGroup
azure group deployment create --template-uri https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.web/web-app-with-redis-cache/azuredeploy.json -g ExampleDeployGroup