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

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

  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 datetime
  3. Select the duration of the SAS access key by selecting end datetime. This is described in the below screensot point 2 and 3.
  4. Click Generate SAS and connection string. Step 4 in the screenshot.
  5. Copy the SAS key provided in the 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@$storageAccount.blob.core.windows.net/"
val confKey = s"fs.azure.sas.$container.$storageAccount.blob.core.windows.net"



try {
  dbutils.fs.mount(
    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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.