Quickstart: Create an Azure synapse workspace with Azure CLI

The Azure CLI is Azure's command-line experience for managing Azure resources. You can use it in your browser with Azure Cloud Shell. You can also install it on macOS, Linux, or Windows and run it from the command line.

In this quickstart, you learn to create a Synapse workspace by using the Azure CLI.

If you don't have an Azure subscription, create an Azure free account before you begin.

Prerequisites

  • Download and install jq, a lightweight and flexible command-line JSON processor

  • Azure Data Lake Storage Gen2 storage account

    Important

    The Azure Synapse workspace needs to be able to read and write to the selected ADLS Gen2 account. In addition, for any storage account that you link as the primary storage account, you must have enabled hierarchical namespace at the creation of the storage account, as described on the Create a Storage Account page.

Create an Azure Synapse workspace using the Azure CLI

  1. Define necessary environment variables to create resources for Azure Synapse workspace.

    Environment Variable Name Description 
    StorageAccountName Name for your existing ADLS Gen2 storage account.
    StorageAccountResourceGroup Name of your existing ADLS Gen2 storage account resource group.
    FileShareName Name of your existing storage file system.
    SynapseResourceGroup Choose a new name for your Azure Synapse resource group.
    Region Choose one of the Azure regions.
    SynapseWorkspaceName Choose a unique name for your new Azure Synapse Workspace.
    SqlUser Choose a value for a new username.
    SqlPassword Choose a secure password.
  2. Create a resource group as a container for your Azure Synapse workspace:

    az group create --name $SynapseResourceGroup --location $Region
    
  3. Create an Azure Synapse Workspace:

    az synapse workspace create \
      --name $SynapseWorkspaceName \
      --resource-group $SynapseResourceGroup \
      --storage-account $StorageAccountName \
      --file-system $FileShareName \
      --sql-admin-login-user $SqlUser \
      --sql-admin-login-password $SqlPassword \
      --location $Region
    
  4. Get Web and Dev URL for Azure Synapse Workspace:

    WorkspaceWeb=$(az synapse workspace show --name $SynapseWorkspaceName --resource-group $SynapseResourceGroup | jq -r '.connectivityEndpoints | .web')
    
    WorkspaceDev=$(az synapse workspace show --name $SynapseWorkspaceName --resource-group $SynapseResourceGroup | jq -r '.connectivityEndpoints | .dev')
    
  5. Create a Firewall Rule to allow your access to Azure Synapse Workspace from your machine:

    ClientIP=$(curl -sb -H "Accept: application/json" "$WorkspaceDev" | jq -r '.message')
    ClientIP=${ClientIP##'Client Ip address : '}
    echo "Creating a firewall rule to enable access for IP address: $ClientIP"
    
    az synapse workspace firewall-rule create --end-ip-address $ClientIP --start-ip-address $ClientIP --name "Allow Client IP" --resource-group $SynapseResourceGroup --workspace-name $SynapseWorkspaceName
    
  6. Open the Azure Synapse Workspace Web URL address stored in environment variable WorkspaceWeb to access your workspace:

    echo "Open your Azure Synapse Workspace Web URL in the browser: $WorkspaceWeb"
    

    Azure Synapse workspace web

  7. Once deployed, additional permissions are required.

  • In the Azure portal, assign other users of the workspace to the Contributor role in the workspace. For detailed steps, see Assign Azure roles using the Azure portal.
  • Assign other users the appropriate Synapse RBAC roles using Synapse Studio.
  • A member of the Owner role of the Azure Storage account must assign the Storage Blob Data Contributor role to the Azure Synapse workspace MSI and other users.

Clean up resources

Follow the steps below to delete the Azure Synapse workspace.

Warning

Deleting an Azure Synapse workspace will remove the analytics engines and the data stored in the database of the contained SQL pools and workspace metadata. It will no longer be possible to connect to the SQL or Apache Spark endpoints. All code artifacts will be deleted (queries, notebooks, job definitions and pipelines).

Deleting the workspace will not affect the data in the Data Lake Store Gen2 linked to the workspace.

If you want to delete the Azure Synapse workspace, complete the following command:

az synapse workspace delete --name $SynapseWorkspaceName --resource-group $SynapseResourceGroup

Next steps

Next, you can create SQL pools or create Apache Spark pools to start analyzing and exploring your data.