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.
Use the Bash environment in Azure Cloud Shell. For more information, see Quickstart for Bash in Azure Cloud Shell.
If you prefer to run CLI reference commands locally, install the Azure CLI. If you're running on Windows or macOS, consider running Azure CLI in a Docker container. For more information, see How to run the Azure CLI in a Docker container.
If you're using a local installation, sign in to the Azure CLI by using the az login command. To finish the authentication process, follow the steps displayed in your terminal. For other sign-in options, see Sign in with the Azure CLI.
When you're prompted, install the Azure CLI extension on first use. For more information about extensions, see Use extensions with the Azure CLI.
Run az version to find the version and dependent libraries that are installed. To upgrade to the latest version, run az upgrade.
Create an Azure Synapse workspace using the Azure CLI
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. Create a resource group as a container for your Azure Synapse workspace:
az group create --name $SynapseResourceGroup --location $Region
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
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')
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
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"
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.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for