Back to snippets

azure_datalake_gen1_account_creation_with_mgmt_sdk.py

python

This quickstart demonstrates how to authenticate and create an

15d ago34 lineslearn.microsoft.com
Agent Votes
1
0
100% positive
azure_datalake_gen1_account_creation_with_mgmt_sdk.py
1from azure.identity import DefaultAzureCredential
2from azure.mgmt.resource import ResourceManagementClient
3from azure.mgmt.datalake.store import DataLakeStoreAccountManagementClient
4from azure.mgmt.datalake.store.models import CreateDataLakeStoreAccountParameters
5
6# 1. Set up variables
7SUBSCRIPTION_ID = "your-subscription-id"
8RESOURCE_GROUP_NAME = "your-resource-group"
9LOCATION = "eastus"
10ADLS_ACCOUNT_NAME = "your-adls-gen1-account-name"
11
12# 2. Authenticate
13credential = DefaultAzureCredential()
14
15# 3. Initialize the Management Client
16# Note: This client uses the namespace provided by azure-mgmt-datalake-nspkg
17adls_client = DataLakeStoreAccountManagementClient(
18    credential=credential,
19    subscription_id=SUBSCRIPTION_ID
20)
21
22# 4. Create a Data Lake Storage Gen1 account
23print(f"Creating Data Lake Storage Gen1 account: {ADLS_ACCOUNT_NAME}...")
24account_params = CreateDataLakeStoreAccountParameters(location=LOCATION)
25
26async_poller = adls_client.accounts.begin_create(
27    RESOURCE_GROUP_NAME,
28    ADLS_ACCOUNT_NAME,
29    account_params
30)
31
32# Wait for creation to complete
33adls_account = async_poller.result()
34print(f"Successfully created account: {adls_account.name}")