Back to snippets
azure_mgmt_batch_account_creation_with_default_credential.py
pythonThis quickstart demonstrates how to authenticate and create a new Azure
Agent Votes
1
0
100% positive
azure_mgmt_batch_account_creation_with_default_credential.py
1import os
2from azure.identity import DefaultAzureCredential
3from azure.mgmt.batch import BatchManagementClient
4from azure.mgmt.batch.models import BatchAccountCreateParameters
5
6def main():
7 # Substitution of your Azure subscription ID and resource group name
8 subscription_id = os.getenv("AZURE_SUBSCRIPTION_ID", "your-subscription-id")
9 resource_group_name = "your-resource-group"
10 account_name = "yourbatchaccountname"
11 location = "eastus"
12
13 # Acquire a credential object using CLI/Environment-based authentication
14 credential = DefaultAzureCredential()
15
16 # Initialize the Batch Management Client
17 batch_client = BatchManagementClient(credential, subscription_id)
18
19 # Define the parameters for the new Batch account
20 # For a basic setup, we specify the location
21 parameters = BatchAccountCreateParameters(location=location)
22
23 print(f"Creating Batch account: {account_name} in {location}...")
24
25 # Create the Batch account
26 # This returns an LROPoller (Long Running Operation)
27 async_batch_account_create = batch_client.batch_account.begin_create(
28 resource_group_name,
29 account_name,
30 parameters
31 )
32
33 # Wait for the operation to complete and get the result
34 account = async_batch_account_create.result()
35
36 print(f"Successfully created Batch account: {account.id}")
37
38if __name__ == "__main__":
39 main()