Getting Started with AzureSDK
Mix.install([
# {:azure_sdk, path: Path.expand("..", __DIR__)},
{:azure_sdk, "~> 0.4.1"},
])
Overview
This notebook creates a Shared Key client against local Azurite, creates a container, uploads a blob, and prints the blob name.
Requires Azurite:
docker compose up -d
Package version:
AzureSDK.version()
Create a client
Path-style endpoints (Azurite) are detected when the URL ends with the account name.
credential =
AzureSDK.Identity.SharedKeyCredential.new(
"devstoreaccount1",
"Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="
)
client =
AzureSDK.Storage.Client.new(
account: "devstoreaccount1",
credential: credential,
endpoint: "http://127.0.0.1:10000/devstoreaccount1"
)
{client.endpoint, AzureSDK.Storage.Client.path_style?(client)}
First upload
container = "livebook-demo"
case AzureSDK.Storage.Container.exists?(client, container) do
true -> :ok
false -> {:ok, _} = AzureSDK.Storage.Container.create(client, container)
{:error, error} -> raise "Azurite Blob is not reachable: #{error.message}"
end
{:ok, blob} =
AzureSDK.Storage.Blob.upload(client, container, "hello.txt", "Hello from Livebook!",
content_type: "text/plain"
)
blob.name
Clean up
{:ok, :deleted} = AzureSDK.Storage.Blob.delete(client, container, "hello.txt")
{:ok, :deleted} = AzureSDK.Storage.Container.delete(client, container)
:ok