How to mount Azure Storage Account to Databricks with SAS key?

In this blog, we will discuss on how to mount Azure storage accounts to Databricks with SAS key. The purpose of this blog post is to mount the storage account in the shortest possible time. Here are the steps involved:

  1. Open the storage account in the Azure Portal and then open the shared access signature key from the left panel.
  2. Select the duration of the SAS access key by selecting the start date time
  3. Select the duration of the SAS access key by selecting the end date time. This is described in the below screenshots (steps 2 and 3).
  4. Click Generate SAS and connection string. Step 4 in the screenshot.
  5. Copy the SAS key provided in step 5 in the screenshot.

Now you have the SAS key for the storage account. Let’s use it in the mounting config as per the below notebook code.

val storageAccount = "put storage account name here"
val container = "Container name to mount "
val sasKey = "Copy the SAS key generated at Step 5"

val mountPoint = s"/mnt/mymountpointname"

try {
  dbutils.fs.unmount(s"$mountPoint") // Use this to unmount as needed
} catch {
  case ioe: java.rmi.RemoteException => println(s"$mountPoint already unmounted")

val sourceString = s"wasbs://$container@$"
val confKey = s"$container.$"

try {
    source = sourceString,
    mountPoint = mountPoint,
    extraConfigs = Map(confKey -> sasKey)
catch {
  case e: Exception =>
    println(s"*** ERROR: Unable to mount $mountPoint. Run previous cells to unmount first")

%fs ls /mnt/mymountpointname/

/*This will list all the files located at the container*/

I hope this post is useful!!

Leave a Reply