Azure for Elixir Developers

Copy Markdown View Source

Azure Storage concepts for Elixir developers new to the platform.

Key Terms

Azure TermAnalogyAzureSDK Module
Storage AccountS3 account namespaceStorage.Client
ContainerS3 bucketStorage.Container
BlobS3 objectStorage.Blob
Access KeyRoot API keySharedKeyCredential
SAS TokenPre-signed URLSASCredential

Your First Upload

credential = SharedKeyCredential.new("myaccount", System.get_env("AZURE_STORAGE_KEY"))

client = Storage.Client.new(account: "myaccount", credential: credential)

{:ok, _} = Container.create(client, "uploads")
{:ok, blob} = Blob.upload(client, "uploads", "hello.txt", "Hello, Azure!")

Every step returns {:ok, result} or {:error, %AzureSDK.Error{}}.

Local Development with Azurite

docker compose up -d
client = Storage.Client.new(
  account: "devstoreaccount1",
  credential: SharedKeyCredential.new("devstoreaccount1",
    "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="),
  endpoint: "http://127.0.0.1:10000/devstoreaccount1"
)

The Azurite key is public — local use only.

Authentication

Shared Key (v0.1.0) — full account access for server-side apps.

SAS (v0.1.0) — time-limited scoped access:

SASCredential.new("sv=2024-11-04&ss=b&sp=r&se=...")

Azure AD (v0.2.0) — OAuth bearer tokens, no shared keys.

Error Handling

case Blob.download(client, "uploads", "missing.txt") do
  {:ok, blob} -> blob.content
  {:error, %Error{status: 404, code: "BlobNotFound"} = e} -> Logger.warning(e.message)
  {:error, %Error{} = e} -> {:error, e}
end

%AzureSDK.Error{} has status, code, message, request_id, service.

Telemetry

:telemetry.attach("app", [:azure_sdk, :blob, :put], fn _, _, %{container: c, name: n}, _ ->
  Logger.info("Uploaded #{c}/#{n}")
end, nil)

What AzureSDK Is

  • Platform SDK for Azure on the BEAM (Blob today, more coming)
  • Req transport, telemetry, retry, standardized errors
  • OTP-ready client structs, no hidden state

What It Isn't (Yet)

  • Full Azure SDK — Queue, Table, Management in later releases
  • SAS generator — v0.1.0 consumes SAS only
  • Terraform replacement — use Management plane (v0.5.0) for provisioning

Next Steps