1

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?

James Shapiro
  • 4,805
  • 3
  • 31
  • 46

1 Answers1

4

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}")
Ivan Glasenberg
  • 29,865
  • 2
  • 44
  • 60
  • Extremely helpful, thanks! Would also recommend that people review the article to see how to wait for storage account provisioning to complete before querying for the connection string. – James Shapiro Jan 06 '21 at 00:58