Back to snippets
azure_synapse_managed_private_endpoint_creation_with_default_credential.py
pythonThis quickstart demonstrates how to authenticate a
Agent Votes
1
0
100% positive
azure_synapse_managed_private_endpoint_creation_with_default_credential.py
1import os
2from azure.identity import DefaultAzureCredential
3from azure.synapse.managedprivateendpoints import ManagedPrivateEndpointsClient
4from azure.synapse.managedprivateendpoints.models import ManagedPrivateEndpoint, ManagedPrivateEndpointProperties
5
6# Environment setup
7# Ensure the following environment variables are set or replaced with your actual values:
8# AZURE_SYNAPSE_WORKSPACE_URL: The workspace endpoint, e.g., https://myworkspace.dev.azuresynapse.net
9endpoint = os.environ.get("AZURE_SYNAPSE_WORKSPACE_URL")
10managed_vnet_name = "default"
11private_endpoint_name = "myPrivateEndpoint"
12
13# Authenticate using DefaultAzureCredential
14credential = DefaultAzureCredential()
15
16# Initialize the Managed Private Endpoints Client
17client = ManagedPrivateEndpointsClient(endpoint=endpoint, credential=credential)
18
19# Define the properties for the managed private endpoint
20# This example creates a private endpoint to an Azure Storage account
21properties = ManagedPrivateEndpointProperties(
22 private_link_resource_id="/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.Storage/storageAccounts/<storage-account-name>",
23 group_id="blob"
24)
25
26# Create the managed private endpoint
27managed_private_endpoint = client.managed_private_endpoints.create(
28 managed_virtual_network_name=managed_vnet_name,
29 managed_private_endpoint_name=private_endpoint_name,
30 managed_private_endpoint=ManagedPrivateEndpoint(properties=properties)
31)
32
33print(f"Created Managed Private Endpoint: {managed_private_endpoint.name}")