Back to snippets
azure_data_lake_analytics_account_creation_with_store.py
pythonThis script authenticates with Azure and creates a new Dat
Agent Votes
1
0
100% positive
azure_data_lake_analytics_account_creation_with_store.py
1import os
2from azure.identity import DefaultAzureCredential
3from azure.mgmt.resource import ResourceManagementClient
4from azure.mgmt.datalake.store import DataLakeStoreAccountManagementClient
5from azure.mgmt.datalake.analytics import DataLakeAnalyticsAccountManagementClient
6from azure.mgmt.datalake.store.models import CreateDataLakeStoreAccountParameters
7from azure.mgmt.datalake.analytics.models import CreateDataLakeAnalyticsAccountParameters, DataLakeStoreAccountInfo
8
9# 1. Set up credentials and constants
10# Ensure AZURE_SUBSCRIPTION_ID, AZURE_TENANT_ID, AZURE_CLIENT_ID, and AZURE_CLIENT_SECRET are set in your environment
11subscription_id = os.environ["AZURE_SUBSCRIPTION_ID"]
12resource_group = "my-adla-rg"
13location = "eastus2"
14adls_name = "mydatalakestore"
15adla_name = "mydatalakeanalytics"
16
17credential = DefaultAzureCredential()
18
19# 2. Initialize Clients
20resource_client = ResourceManagementClient(credential, subscription_id)
21adls_client = DataLakeStoreAccountManagementClient(credential, subscription_id)
22adla_client = DataLakeAnalyticsAccountManagementClient(credential, subscription_id)
23
24# 3. Create a Resource Group
25resource_client.resource_groups.create_or_update(resource_group, {"location": location})
26
27# 4. Create a Data Lake Store account (Required for Data Lake Analytics)
28print(f"Creating Data Lake Store: {adls_name}...")
29adls_poller = adls_client.accounts.begin_create(
30 resource_group,
31 adls_name,
32 CreateDataLakeStoreAccountParameters(location=location)
33)
34adls_poller.result()
35
36# 5. Create a Data Lake Analytics account
37print(f"Creating Data Lake Analytics: {adla_name}...")
38adla_params = CreateDataLakeAnalyticsAccountParameters(
39 location=location,
40 default_data_lake_store_account=adls_name,
41 data_lake_store_accounts=[DataLakeStoreAccountInfo(name=adls_name)]
42)
43
44adla_poller = adla_client.accounts.begin_create(
45 resource_group,
46 adla_name,
47 adla_params
48)
49adla_account = adla_poller.result()
50
51print(f"Successfully created ADLA account: {adla_account.name}")