Quickstart: Create an Azure Synapse Analytics workspace with the 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 how to create an Azure Synapse Analytics 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

    An Azure Synapse Analytics workspace needs to be able to read and write to the selected Data Lake Storage 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 in Create a storage account.

Create an Azure Synapse Analytics workspace by using the Azure CLI

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

    Environment Variable name Description 
    StorageAccountName Name for your existing Data Lake Storage Gen2 storage account.
    StorageAccountResourceGroup Name of your existing Data Lake Storage Gen2 storage account resource group.
    FileShareName Name of your existing storage file system.
    SynapseResourceGroup Choose a new name for your Azure Synapse Analytics resource group.
    Region Choose one of the Azure regions.
    SynapseWorkspaceName Choose a unique name for your new Azure Synapse Analytics 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 Analytics workspace:

    az group create --name $SynapseResourceGroup --location $Region
    
  3. Create an Azure Synapse Analytics 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 the web and dev URLs for the Azure Synapse Analytics 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 access to your Azure Synapse Analytics 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 Analytics workspace web URL address stored in the environment variable WorkspaceWeb to access your workspace:

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

    Screenshot that shows the Azure Synapse Analytics workspace web.

  7. After it's deployed, more permissions are required:

Clean up resources

Follow these steps to delete the Azure Synapse Analytics workspace.

Warning

Deleting an Azure Synapse Analytics workspace removes 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 won't affect the data in the Data Lake Storage Gen2 account linked to the workspace.

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

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

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