Reputation: 6186
Suppose that you have admin access and you have just created a storage account programmatically in a Python script.
How can you then retrieve a connection string from that newly created storage account in Python? For example, if you wanted to create Storage Queues within the same script?
Upvotes: 1
Views: 2400
Reputation: 29940
If you're using azure-mgmt-storage to create the storage account, then you can follow this article to fetch the connection string.
Here is the code snippet in the sample above to fetch connection string:
# Step 3: Retrieve the account's primary access key and generate a connection string.
keys = storage_client.storage_accounts.list_keys(RESOURCE_GROUP_NAME, STORAGE_ACCOUNT_NAME)
print(f"Primary key for storage account: {keys.keys[0].value}")
conn_string = f"DefaultEndpointsProtocol=https;EndpointSuffix=core.windows.net;AccountName={STORAGE_ACCOUNT_NAME};AccountKey={keys.keys[0].value}"
print(f"Connection string: {conn_string}")
Upvotes: 5