Bring your own Storage to App Service now in Public Preview
We’re excited to announce the “Bring Your Own Storage” feature to App Service on Linux and Web App for Containers. Available in public preview, “Bring Your Own Storage” supports mounting Azure Blobs and Azure Files into your Azure App Service. You can configure up to five Azure storage accounts for a given App Service.
“Bring your own storage” for example, enables the following scenarios:
- Bring your own content and have it readily available for your web application hosted on App Service. This avoids the need to copy the content which could take a lot of time depending on the number and size of the files.
- Use the azure blob storage or azure files to write content or Log files which can be shared across different services you might have. For example, you can use any log management service like splunk with your app service writing logs to the azure files or blob storage and the log management service can consume the logs from the storage.
Configure azure storage account on App Service
With this public preview annoucement,
Azure CLI will have support for “Bring your own storage”. The UX experience is coming soon.
Login to the CLI and ensure you have selected the right subscription:
$ az login
$ az account list
$ az account set –subscription “YourSubscriptionName”
To get help on the command to manage storage accounts on your app service, use the -h option:
az webapp config storage-account -h
Group
az webapp config storage-account : Manage a web app's Azure storage account configurations.
Commands:
add : Add an Azure storage account configuration to a web app.
delete : Delete a web app's Azure storage account configuration.
list : Get a web app's Azure storage account configurations.
update : Update an existing Azure storage account configuration on a web app.
Add a storage account to your app service
To add a new storage account, you will need an Azure Storage (blob or azure files). If you haven’t created one yet, please follow the steps mentioned
here to create one.
Also, to learn more about how to create App Service, please follow the steps
here.
To link a storage account with your App Service (assumes you have already created the app service and the storage account), use the following command:
$ az webapp config storage-account add -g RESOURCE_GROUP -n APP_NAME \
--custom-id CustomId [Unique identifier for this storage mapping] \
--storage-type [Azure storage type: AzureFiles or AzureBlob] \
--account-name [Azure storage account name] \
--share-name [Azure storage share/file name] \
--access-key [storage access key] \
--mount-path [/path/to/mount within the container]
Sample:
$ az webapp config storage-account add -g AppSvcBYOSDemoSite -n AppSvcBYOSDemoSite --custom-id MediaVolume --storage-type AzureBlob --account-name appsvcbyosdemo --share-name mediablob --access-key <youraccesskey> --mount-path /var/media
Output:
{
"MediaVolume": {
"accessKey": "youraccesskey",
"accountName": "appsvcbyosdemo",
"mountPath": "/var/media",
"shareName": "mediablob",
"state": "Ok",
"type": "AzureBlob"
}
}
At this point, your web application will have the storage mounted at /var/media and your web application has full access to this storage.
If you want to use the mounted storage account in a Multi-container web app, you need to specify the custom-id of your storage account in the volumes block of your container definition in the Docker-Compose or Kubernetes yaml file, for example:
version: '3'
services:
web:
image: "mydocker/image:latest"
ports:
- "80:80"
volumes:
- <custom-id>:/var/media
redis:
image: "redis:alpine"
List storage accounts associated with the App Service
To list the storage accounts associated with your app service, use the list command:
$ az webapp config storage-account list -g RESOURCE_GROUP -n NAME
Sample:
$ az webapp config storage-account list -g AppSvcBYOSDemoSite -n AppSvcBYOSDemoSite
Output:
[
{
"name": "MediaVolume",
"slotSetting": false,
"value": {
"accessKey": "youraccesskey",
"accountName": "appsvcbyosdemo",
"mountPath": "/var/media",
"shareName": "mediablob",
"state": "Ok",
"type": "AzureBlob"
}
}
]
Update storage account associated with the App Service
To update the storage accounts associated with your app service, use the update command:
$ az webapp config storage-account update -g RESOURCE_GROUP -n APP_NAME \
--custom-id CustomId [Unique identifier for this storage mapping] \
--storage-type [Azure storage type: AzureFiles or AzureBlob] \
--account-name [Azure storage account name] \
--share-name [Azure storage share/file name] \
--access-key [storage access key] \
--mount-path [/path/to/mount within the container]
Sample:
$ az webapp config storage-account update -g AppSvcBYOSDemoSite -n AppSvcBYOSDemoSite --custom-id MediaVolume --storage-type AzureBlob --account-name appsvcbyosdemo --share-name mediablob --access-key <youraccesskey> --mount-path /var/media
Output:
{
"MediaVolume": {
"accessKey": "youraccesskey",
"accountName": "appsvcbyosdemo",
"mountPath": "/var/media",
"shareName": "mediablob",
"state": "Ok",
"type": "AzureBlob"
}
}
Remove storage account associated with the App Service
To remove the storage account from the Azure App Service, use the delete command.
$ az webapp config storage-account delete -g RESOURCE_GROUP -n APP_NAME --custom-id CustomId
Sample:
az webapp config storage-account delete -g AppSvcBYOSDemoSite -n AppSvcBYOSDemoSite --custom-id MediaVolume
Output:
{}
Sample Web Application that uses external Azure Storage for static files
Here is a sample
dotnetcore web application that shows how you easy it is to use an Azure Storage account to store your content and reference it in your web application.
Useful Links