Bring Your Own Storage in Azure Web App
Published Jul 27 2021 04:56 PM 9,479 Views
Microsoft

This article will show you a general idea on how to Mount Azure Storage as a local share in a container app in App Service

and some key points when use it.

 

1. What is Bring your own storage(BYOS)?

BYOS means bring your own Azure Storage File share or Blob container into Azure Container Web App as network file share.

It supports Azure Linux Web App and Windows Container Web App, but does not support Azure Function Apps as of now. (Linux Function App cannot be configured from portal but can be configured via Azure CLI)

With BYOS, you do not need to rewrite code to use Storage SDK. Compared to Mount SMB Azure file share on Linux VM, it is much easier for using.

 

2. How to use it?

We can use it by simply clicking on Azure Portal:

Haoran_Li_0-1625552490041.jpeg

Or use Azure CLI, note that "custom-id" should be unique:

az webapp config storage-account add --resource-group <group-name> --name <app-name> --custom-id <custom-id> --storage-type <AzureFiles/AzureBlob> --share-name <share-name> --account-name <storage-account-name> --access-key "<access-key>" --mount-path <mount-path-directory>

Haoran_Li_1-1625552490045.jpeg

Also, you can integrate it with ARM template:

https://github.com/Azure/app-service-linux-docs/blob/master/BringYourOwnStorage/BYOS_azureFiles.json

"resources": [
  {
      "type""Microsoft.Web/sites",
      "apiVersion""2018-11-01",
      "name""[parameters('webApp_Name')]",
      "location""[parameters('webApp_Location')]",
      "properties": {
          "siteConfig": {
              "azureStorageAccounts": {
                  "[parameters('BYOS_mountName')]": {
                      "mountPath""[parameters('BYOS_mountPath')]",
                      "accountName""[parameters('AzureStorage_AccountName')]",
                      "type""AzureFiles",
                      "shareName""[parameters('AzureStorage_ShareName')]",
                      "accessKey"""
                  }
              }
          }
      }
  }
]

 

3. Some key points:

  • When using AzureFiles, it mounted as CIFS with read/write permission, when using AzureBlob, it mounted as blobfuse with readonly permission.
  • Azure Storage in App Service lets you specify up to five mount points per app.
  • Azure Storage mounted to an app is not accessible through App Service FTP/FTPs endpoints.
  • Storage mounts are not backed up when you back up your app
  • It is not recommended to put the Storage Account in a different region from the Web App because this adds latency. Latency between App Service and Storage can cause crashes due to not being able to mount the Storage share. 
  • The share name for AzureFiles should come from Files shares in Storage Account

Haoran_Li_2-1625552490046.png

 

  • The share name for AzureBlob should come from Containers in Storage Account

Haoran_Li_3-1625552490047.png

  • If we mount the blob container as AzureFile in Advanced mode, the web app will crash.

After mounting, the web app will restart automatically, then we can check the mount info via ‘cat /etc/mtab’.

Haoran_Li_4-1625552490052.jpeg

 

  • For AzureFiles, it will be shown as cifs rw, which means read/write. For AzureBlob, it will be shown as fuse ro, which means readonly.

 

4. What is CIFS? And related issue.

Common Internet File System (CIFS) is a network filesystem protocol used for providing shared access to files and printers between machines on the network. A CIFS client application can read, write, edit and even remove files on the remote server. CIFS client can communicate with any server that is set up to receive a CIFS client request.

https://docs.microsoft.com/en-us/windows/win32/fileio/microsoft-smb-protocol-and-cifs-protocol-overv...

 

When use CIFS, local databases (eg SQLLite) or other components that rely on file handles/locks may get problem.

 

Haoran_Li_5-1625552490048.png

One workaround for the sqlite issue is changing the journal mode to wal by using below command:

sqlite3 <database-file> 'PRAGMA journal_mode=wal;'

There are advantages and disadvantages to using WAL instead of a rollback journal. Please read this reference carefully before using it: https://sqlite.org/wal.html 

 

Thanks for reading this post. I hope you liked it. Please feel free to write your comments and views about the same over here.

 

Co-Authors
Version history
Last update:
‎Nov 01 2021 05:30 AM
Updated by: