Synapse: Mounts

(Last Updated On: )

This post is how to work with mounts on Synapse.

I suggest mounting to an ADLS storage account. That is what I will assume in the below examples.

List Mounts
  1. from notebookutils import mssparkutils
  2.  
  3. mssparkutils.fs.mounts()
Get Mount Path

The output of this command will produce ‘/synfs/<number>/mnt/<CONTAINER_NAME>’

  1. from notebookutils import mssparkutils
  2.  
  3. mount_name = "/mnt/<CONTAINER_NAME>"
  4. mount_path = mssparkutils.fs.getMountPath(mount_name)
Unmount
  1. from notebookutils import mssparkutils
  2.  
  3. mount_name = "/mnt/<CONTAINER_NAME>"
  4. mssparkutils.fs.unmount(mount_name)
Mount Using a Linked Service

First you must have a linked service created to the storage account. This linked service must be hard-coded and not parameterized in any way.

  1. from notebookutils import mssparkutils
  2.  
  3. container = '<CONTAINER_NAME>'
  4. storage_account = '<STORAGE_ACCOUNT_NAME>'
  5. sub_folder = '<SUB_FOLDER>' #it should be noted that this isn't required.
  6. linked_service_name = '<LINKED_SERVICE_NAME>'
  7.  
  8. mssparkutils.fs.mount(
  9. source='abfss://%s@%s.dfs.core.windows.net/%s/' % (container, storage_account, sub_folder),
  10. mountPoint='/mnt/%s' % (container),
  11. {'linkedService':linked_service_name, 'fileCacheTimeout': 120, 'timeout': 120}
  12. )
Mount Using Configs

You will need to get the secret. Refer to Synapse: Get Secret

  1. from notebookutils import mssparkutils
  2.  
  3. client_id = '<CLIENT_ID>'
  4. tenant_id = '<TENANT_ID>'
  5. container = '<CONTAINER_NAME>'
  6. storage_account = '<STORAGE_ACCOUNT_NAME>'
  7. sub_folder = '<SUB_FOLDER>' #it should be noted that this isn't required.
  8.  
  9. configs = {
  10. "fs.azure.account.auth.type": "OAuth",
  11. "fs.azure.account.oauth.provider.type": "org.apache.fs.azurebfs.oauth2.ClientCredsTokenProvider",
  12. "fs.azure.account.oauth2.client.id": client_id,
  13. "fs.azure.account.oauth2.client.secret": secret,
  14. "fs.azure.account.oauth2.client.endpoint": "https://login.microsoftonline.com/" tenant_id + "/oauth2/token"
  15. }
  16.  
  17. mssparkutils.fs.mount(
  18. source='abfss://%s@%s.dfs.core.windows.net/%s' % (container, storage_account, sub_folder),
  19. mountPoint='/mnt/%s' % (container),
  20. extraConfigs=configs
  21. )