Migrating from Azurex

Copy Markdown View Source

Azurex served Elixir Blob Storage needs. AzureSDK is the successor platform SDK.

Why Migrate?

  • Platform scope (Queue, Table, Management coming)
  • Built-in :telemetry
  • %AzureSDK.Error{} everywhere
  • Req/Finch instead of HTTPoison
  • Azurite-first CI
  • Explicit credentials; OAuth in v0.2.0

See plans/azurex-review.md for details.

Dependency

# Remove: {:azurex, "~> 1.1"}
# Add:
{:azure_sdk, "~> 0.1.0"}

Client Setup

Azurex: config-based or inline keys at call site.

AzureSDK:

credential = SharedKeyCredential.new(account, key)
client = Storage.Client.new(account: account, credential: credential)
Blob.upload(client, container, blob, content)

Create client once at startup; pass to all operations.

Operation Mapping

AzurexAzureSDK
put_blob/4Blob.upload/4
get_blob/3Blob.download/3
delete_blob/3Blob.delete/3
list_blobs/2Container.list_blobs/2
create_container/2Container.create/2
delete_container/2Container.delete/2
list_containers/1Container.list/1

Returns structured maps, not raw HTTP:

{:ok, blob} = Blob.download(client, "c", "f.txt")
blob.content
blob.properties.etag

Errors

case Blob.download(client, c, n) do
  {:ok, %{content: data}} -> data
  {:error, %Error{status: 404}} -> nil
  {:error, %Error{} = e} -> {:error, e}
end

Config Migration

def azure_client do
  Storage.Client.new(
    account: System.get_env("AZURE_STORAGE_ACCOUNT"),
    credential: SharedKeyCredential.new(
      System.get_env("AZURE_STORAGE_ACCOUNT"),
      System.get_env("AZURE_STORAGE_KEY")
    )
  )
end

Azurite

Storage.Client.new(
  account: "devstoreaccount1",
  credential: SharedKeyCredential.new("devstoreaccount1", "..."),
  endpoint: "http://127.0.0.1:10000/devstoreaccount1"
)

Double-account signing handled automatically.

Not Yet in AzureSDK

FeatureStatus
SAS generationPlanned
Page blobsBlock blobs only
Queue/Tablev0.3.0 / v0.4.0

Incremental Strategy

  1. Add azure_sdk alongside azurex
  2. Create client in context module
  3. Migrate one operation at a time
  4. Add telemetry handlers
  5. Remove azurex

Further Reading