お金をかけずにサーバーの勉強をしよう

Azure Storageエミュレーター Azuriteを使う

2022年6月2日

メニューへ戻る

昨今はパブリッククラウドのお仕事をするサーバーエンジニアやプログラマが増えていると思いますが、パブリッククラウドの機能に触れて実践的な経験を積むには、パブリッククラウドにお金を払わねばなりません。

しかしこれがかなり高い!

法人が契約するならなんてことのない費用なんでしょうが、個人が契約するには月々のお小遣いのレベルではありません。

使っている時間分だけ課金されるのならまだ良いのですが、ストレージ利用料はデータを置いている間はずっと課金されてしまいます。

土日しか時間が割けない人の場合は結局1月分丸々課金されたりして、コストパフォーマンスが非常に悪いのです。

そこでパブリッククラウドのエミュレーターはないものか…と探してみると、わずかではありますが無いこともないです。

ここでは、Azure Storageのエミュレーターである Azurite(アズライト)をインストールして Azure CLIから使ってみるというお勉強をします。

Azuriteでエミュレートするのは、Blob/Queue/Tableの3つです。
※TableはPreviewです。

構成としてはこのようにします。
Azurite 1

前提として以下の環境を使います。

・Ubuntu Server 22.04
 (前編)Ubuntu Linux Desktop 用の仮想マシンを作る
 (後編)Ubuntu Linux Desktop をインストール
・Ubuntu Desktop 22.04
 Ubuntu Linux Server をインストール
・Node.js
 Node.js インストール
 ※但しここでは Ubuntu Server 22.04にインストールします。
・Azure Command Line Interface(CLI)
 Ubuntu Desktop 22.04にインストールします。

では、1つ1つ。


●Ubuntu Server 22.04に Node.jsをインストール

Azuriteは Node.jsの上で動くものですので、まず Node.js環境を作ります。
Node.js インストールに書いている手順を Ubuntu Serverでやるだけです。

subro@UbuntuServer2204:~/work$ curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
[sudo] subro のパスワード: パスワードを入れる

## Installing the NodeSource Node.js 16.x repo...


## Populating apt-get cache...

+ apt-get update
ヒット:1 https://download.docker.com/linux/ubuntu jammy InRelease
ヒット:2 http://jp.archive.ubuntu.com/ubuntu jammy InRelease
取得:3 http://jp.archive.ubuntu.com/ubuntu jammy-updates InRelease [109 kB]
取得:4 http://jp.archive.ubuntu.com/ubuntu jammy-backports InRelease [99.8 kB]
取得:5 http://jp.archive.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
取得:6 http://jp.archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages [216 kB]
取得:7 http://jp.archive.ubuntu.com/ubuntu jammy-updates/universe amd64 Packages [102 kB]
取得:8 http://jp.archive.ubuntu.com/ubuntu jammy-security/main amd64 Packages [129 kB]
取得:9 http://jp.archive.ubuntu.com/ubuntu jammy-security/main Translation-en [33.8 kB]
801 kB を 2秒 で取得しました (424 kB/s)
パッケージリストを読み込んでいます... 完了

## Confirming "jammy" is supported...

+ curl -sLf -o /dev/null 'https://deb.nodesource.com/node_16.x/dists/jammy/Release'

## Adding the NodeSource signing key to your keyring...

+ curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | tee /usr/share/keyrings/nodesource.gpg >/dev/null

## Creating apt sources list file for the NodeSource Node.js 16.x repo...

+ echo 'deb [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_16.x jammy main' > /etc/apt/sources.list.d/nodesource.list
+ echo 'deb-src [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_16.x jammy main' >> /etc/apt/sources.list.d/nodesource.list

## Running `apt-get update` for you...

+ apt-get update
ヒット:1 http://jp.archive.ubuntu.com/ubuntu jammy InRelease
ヒット:2 https://download.docker.com/linux/ubuntu jammy InRelease
ヒット:3 http://jp.archive.ubuntu.com/ubuntu jammy-updates InRelease
ヒット:4 http://jp.archive.ubuntu.com/ubuntu jammy-backports InRelease
取得:5 https://deb.nodesource.com/node_16.x jammy InRelease [4,583 B]
ヒット:6 http://jp.archive.ubuntu.com/ubuntu jammy-security InRelease
取得:7 https://deb.nodesource.com/node_16.x jammy/main amd64 Packages [774 B]
5,357 B を 1秒 で取得しました (9,377 B/s)
パッケージリストを読み込んでいます... 完了

## Run `sudo apt-get install -y nodejs` to install Node.js 16.x and npm
## You may also need development tools to build native addons:
     sudo apt-get install gcc g++ make
## To install the Yarn package manager, run:
     curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
     echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
     sudo apt-get update && sudo apt-get install yarn


subro@UbuntuServer2204:~/work$ sudo apt-get install -y nodejs
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています... 完了
状態情報を読み取っています... 完了
以下のパッケージが新たにインストールされます:
  nodejs
アップグレード: 0 個、新規インストール: 1 個、削除: 0 個、保留: 5 個。
26.4 MB のアーカイブを取得する必要があります。
この操作後に追加で 124 MB のディスク容量が消費されます。
取得:1 https://deb.nodesource.com/node_16.x jammy/main amd64 nodejs amd64 16.15.0-deb-1nodesource1 [26.4 MB]
26.4 MB を 2秒 で取得しました (10.8 MB/s)
以前に未選択のパッケージ nodejs を選択しています。
(データベースを読み込んでいます ... 現在 110015 個のファイルとディレクトリがインストールされています。)
.../nodejs_16.15.0-deb-1nodesource1_amd64.deb を展開する準備をしています ...
nodejs (16.15.0-deb-1nodesource1) を展開しています...
nodejs (16.15.0-deb-1nodesource1) を設定しています ...
man-db (2.10.2-1) のトリガを処理しています ...
Scanning processes...
Scanning linux images...

Running kernel seems to be up-to-date.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.

subro@UbuntuServer2204:~/work$ node --version
v16.15.0

インストールできました。


●Azuriteインストール

Azuriteは GitHubで公開されています。
ダウンロードはこちら。

GitHub Azure / Arurite

2022年6月2日時点での最新版は、3.17.1でした。

[Getting Started]の段落の[NPM]の項にインストール方法と実行方法が書いてあります。
Node.jsの npmコマンドでインストールします。
npmコマンドには -g オプションを与えていてグローバルインストールとなり、root権限が必要ですので sudoコマンドも使います。

subro@UbuntuServer2204:~/work$ sudo npm install -g azurite
[sudo] subro のパスワード: パスワードを入れる
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.

added 292 packages, and audited 293 packages in 17s

45 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
npm notice
npm notice New minor version of npm available! 8.5.5 -> 8.12.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.12.0
npm notice Run npm install -g npm@8.12.0 to update!
npm notice

インストールできました。

次に早速実行と行きたいのですが、デフォルトではループバックインターフェイス(127.0.0.1)でしか待ち受けしないので、Ubuntu Desktopからのアクセスに応答しません。

全てのネットワークインターフェイスで待ち受けるよう、コマンドにオプションが必要です。

[Supported Command Line Options]の段落の[Allow Accepting Requests from Remote (potentially unsafe)]の項にあるオプションです。

ここまで見た所で実行コマンドはできるのですが、まだ慌ててはいけません

Azuriteは Azure Storageのエミュレーターですので、データの置き場所が必要です。
どこかディスク上のディレクトリを決めてそれを -l オプションに与えます。

ここでは、Azuriteを rootでインストールしているのでチグハグになってしまいますが、subroのホームディレクトリの下に azuriteディレクトリを作り、そこをデータ保存用ディレクトリとし、Azuriteも subroで実行するようにしました。

それではやっとこ実行です。
-sオプションがサイレントモードで標準出力にメッセージを出さず、-dオプションがデバッグモードでメッセージを指定されたログファイルに出力します。

subro@UbuntuServer2204:~$ mkdir azurite
subro@UbuntuServer2204:~$ ls -l azurite
合計 0

subro@UbuntuServer2204:~$ azurite -s -l ~/azurite -d ~/azurite/debug.log --blobHost 0.0.0.0 --queueHost 0.0.0.0 --tableHost 0.0.0.0 &
[1] 3345

Azurite Blob service is starting at http://0.0.0.0:10000
Azurite Blob service is successfully listening at http://0.0.0.0:10000
Azurite Queue service is starting at http://0.0.0.0:10001
Azurite Queue service is successfully listening at http://0.0.0.0:10001
Azurite Table service is starting at http://0.0.0.0:10002
Azurite Table service is successfully listening at http://0.0.0.0:10002

動きました。
Blob/Queue/Tableそれぞれを別ポートに割り当てて、別なエンドポイントを構成していることが分かります。


●Ubuntu Desktop 22.04に Azure CLIをインストール

Azure CLIはエミュレーターではなく本物です。
インストールの仕方はこちら。

Linux に Azure CLI をインストールする

こちらのインストール オプションにある、オプション 1: 1 つのコマンドでインストールするの方法でインストールしてみます。

subro@Ubuntu2204:~$ curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
ヒット:1 http://jp.archive.ubuntu.com/ubuntu jammy InRelease
取得:2 http://jp.archive.ubuntu.com/ubuntu jammy-updates InRelease [109 kB]
取得:3 http://jp.archive.ubuntu.com/ubuntu jammy-backports InRelease [99.8 kB]
取得:4 http://jp.archive.ubuntu.com/ubuntu jammy-updates/main i386 Packages [101 kB]
取得:5 http://jp.archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages [216 kB]
取得:6 http://jp.archive.ubuntu.com/ubuntu jammy-updates/main Translation-en [55.5 kB]
取得:7 http://jp.archive.ubuntu.com/ubuntu jammy-updates/main amd64 DEP-11 Metadata [57.6 kB]
取得:8 http://jp.archive.ubuntu.com/ubuntu jammy-updates/main amd64 c-n-f Metadata [3,716 B]
取得:9 http://jp.archive.ubuntu.com/ubuntu jammy-updates/universe amd64 Packages [102 kB]
取得:10 http://jp.archive.ubuntu.com/ubuntu jammy-updates/universe Translation-en [34.0 kB]
取得:11 http://jp.archive.ubuntu.com/ubuntu jammy-updates/universe amd64 DEP-11 Metadata [91.9 kB]
取得:12 http://jp.archive.ubuntu.com/ubuntu jammy-updates/universe DEP-11 48x48 Icons [35.1 kB]
取得:13 http://jp.archive.ubuntu.com/ubuntu jammy-updates/universe DEP-11 64x64 Icons [46.5 kB]
取得:14 http://jp.archive.ubuntu.com/ubuntu jammy-updates/universe amd64 c-n-f Metadata [1,848 B]
取得:15 http://jp.archive.ubuntu.com/ubuntu jammy-backports/universe amd64 DEP-11 Metadata [1,196 B]
取得:16 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
取得:17 http://security.ubuntu.com/ubuntu jammy-security/main amd64 Packages [129 kB]
取得:18 http://security.ubuntu.com/ubuntu jammy-security/main i386 Packages [44.5 kB]
取得:19 http://security.ubuntu.com/ubuntu jammy-security/main Translation-en [33.8 kB]
取得:20 http://security.ubuntu.com/ubuntu jammy-security/main amd64 DEP-11 Metadata [11.4 kB]
取得:21 http://security.ubuntu.com/ubuntu jammy-security/main amd64 c-n-f Metadata [2,116 B]
取得:22 http://security.ubuntu.com/ubuntu jammy-security/universe amd64 Packages [59.5 kB]
取得:23 http://security.ubuntu.com/ubuntu jammy-security/universe i386 Packages [15.7 kB]
取得:24 http://security.ubuntu.com/ubuntu jammy-security/universe amd64 c-n-f Metadata [960 B]
1,364 kB を 2秒 で取得しました (546 kB/s)

パッケージリストを読み込んでいます... 完了
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています... 完了
状態情報を読み取っています... 完了
gnupg はすでに最新バージョン (2.2.27-3ubuntu2) です。
gnupg は手動でインストールしたと設定されました。
lsb-release はすでに最新バージョン (11.1.0ubuntu4) です。
lsb-release は手動でインストールしたと設定されました。
curl はすでに最新バージョン (7.81.0-1ubuntu1.2) です。
以下のパッケージが新たにインストールされます:
  apt-transport-https
アップグレード: 0 個、新規インストール: 1 個、削除: 0 個、保留: 21 個。
1,512 B のアーカイブを取得する必要があります。
この操作後に追加で 169 kB のディスク容量が消費されます。
取得:1 http://jp.archive.ubuntu.com/ubuntu jammy/universe amd64 apt-transport-https all 2.4.5 [1,512 B]
1,512 B を 0秒 で取得しました (15.4 kB/s)
以前に未選択のパッケージ apt-transport-https を選択しています。
(データベースを読み込んでいます ... 現在 203447 個のファイルとディレクトリがインストールされています。)
.../apt-transport-https_2.4.5_all.deb を展開する準備をしています ...
apt-transport-https (2.4.5) を展開しています...
apt-transport-https (2.4.5) を設定しています ...
ヒット:1 http://jp.archive.ubuntu.com/ubuntu jammy InRelease
ヒット:2 http://jp.archive.ubuntu.com/ubuntu jammy-updates InRelease
ヒット:3 http://jp.archive.ubuntu.com/ubuntu jammy-backports InRelease
取得:4 https://packages.microsoft.com/repos/azure-cli jammy InRelease [10.4 kB]
ヒット:5 http://security.ubuntu.com/ubuntu jammy-security InRelease
取得:6 https://packages.microsoft.com/repos/azure-cli jammy/main amd64 Packages [888 B]
11.3 kB を 1秒 で取得しました (16.8 kB/s)
パッケージリストを読み込んでいます... 完了
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています... 完了
状態情報を読み取っています... 完了
以下のパッケージが新たにインストールされます:
  azure-cli
アップグレード: 0 個、新規インストール: 1 個、削除: 0 個、保留: 21 個。
80.0 MB のアーカイブを取得する必要があります。
この操作後に追加で 1,060 MB のディスク容量が消費されます。
取得:1 https://packages.microsoft.com/repos/azure-cli jammy/main amd64 azure-cli all 2.37.0-1~jammy [80.0 MB]
80.0 MB を 14秒 で取得しました (5,910 kB/s)
以前に未選択のパッケージ azure-cli を選択しています。
(データベースを読み込んでいます ... 現在 203451 個のファイルとディレクトリがインストールされています。)
.../azure-cli_2.37.0-1~jammy_all.deb を展開する準備をしています ...
azure-cli (2.37.0-1~jammy) を展開しています...
azure-cli (2.37.0-1~jammy) を設定しています ...

インストールできました。

azコマンド(実体はPythonのスクリプト)が使えるようになりました。

subro@Ubuntu2204:~$ az

Welcome to Azure CLI!
---------------------
Use `az -h` to see available commands or go to https://aka.ms/cli.

Telemetry
---------
The Azure CLI collects usage data in order to improve your experience.
The data is anonymous and does not include commandline argument values.
The data is collected by Microsoft.

You can change your telemetry settings with `az configure`.


     /\
    /  \    _____   _ _  ___ _
   / /\ \  |_  / | | | \'__/ _\
  / ____ \  / /| |_| | | |  __/
 /_/    \_\/___|\__,_|_|  \___|


Welcome to the cool new Azure CLI!

Use `az --version` to display the current version.
Here are the base commands:

    account             : Manage Azure subscription information.
    acr                 : Manage private registries with Azure Container Registries.
    ad                  : Manage Azure Active Directory Graph entities needed for Role Based Access
                         Control.
    advisor             : Manage Azure Advisor.
    afd                 : Manage Azure Front Door Standard/Premium. For classical Azure Front Door,
                         please refer https://docs.microsoft.com/en-us/cli/azure/network/front-
                         door?view=azure-cli-latest.
    aks                 : Manage Azure Kubernetes Services.
    ams                 : Manage Azure Media Services resources.
    apim                : Manage Azure API Management services.
    appconfig           : Manage App Configurations.
    appservice          : Manage App Service plans.
    aro                 : Manage Azure Red Hat OpenShift clusters.
    backup              : Manage Azure Backups.
    batch               : Manage Azure Batch.
    bicep               : Bicep CLI command group.
    billing             : Manage Azure Billing.
    bot                 : Manage Microsoft Azure Bot Service.
    cache               : Commands to manage CLI objects cached using the `--defer` argument.
    capacity            : Manage capacity.
    cdn                 : Manage Azure Content Delivery Networks (CDNs).
    cloud               : Manage registered Azure clouds.
    cognitiveservices   : Manage Azure Cognitive Services accounts.
    config              : Manage Azure CLI configuration.
    configure           : Manage Azure CLI configuration. This command is interactive.
    consumption         : Manage consumption of Azure resources.
    container           : Manage Azure Container Instances.
    cosmosdb            : Manage Azure Cosmos DB database accounts.
    databoxedge         : Support data box edge device and management.
    deployment          : Manage Azure Resource Manager template deployment at subscription scope.
    deployment-scripts  : Manage deployment scripts at subscription or resource group scope.
    deploymentmanager   : Create and manage rollouts for your service.
    disk                : Manage Azure Managed Disks.
    disk-access         : Manage disk access resources.
    disk-encryption-set : Disk Encryption Set resource.
    dla                 : Manage Data Lake Analytics accounts, jobs, and catalogs.
    dls                 : Manage Data Lake Store accounts and filesystems.
    dms                 : Manage Azure Data Migration Service (DMS) instances.
    eventgrid           : Manage Azure Event Grid topics, domains, domain topics, system topics
                         partner topics, event subscriptions, system topic event subscriptions and
                         partner topic event subscriptions.
    eventhubs           : Manage Azure Event Hubs namespaces, eventhubs, consumergroups and geo
                         recovery configurations - Alias.
    extension           : Manage and update CLI extensions.
    feature             : Manage resource provider features.
    feedback            : Send feedback to the Azure CLI Team.
    find                : I'm an AI robot, my advice is based on our Azure documentation as well as
                         the usage patterns of Azure CLI and Azure ARM users. Using me improves
                         Azure products and documentation.
    functionapp         : Manage function apps. To install the Azure Functions Core tools see
                         https://github.com/Azure/azure-functions-core-tools.
    group               : Manage resource groups and template deployments.
    hdinsight           : Manage HDInsight resources.
    identity            : Managed Identities.
    image               : Manage custom virtual machine images.
    interactive         : Start interactive mode. Installs the Interactive extension if not
                         installed already.
    iot                 : Manage Internet of Things (IoT) assets.
    keyvault            : Manage KeyVault keys, secrets, and certificates.
    kusto               : Manage Azure Kusto resources.
    lab                 : Manage Azure DevTest Labs.
    lock                : Manage Azure locks.
    logicapp            : Manage logic apps.
    login               : Log in to Azure.
    logout              : Log out to remove access to Azure subscriptions.
    managed-cassandra   : Azure Managed Cassandra.
    managedapp          : Manage template solutions provided and maintained by Independent Software
                         Vendors (ISVs).
    managedservices     : Manage the registration assignments and definitions in Azure.
    maps                : Manage Azure Maps.
    mariadb             : Manage Azure Database for MariaDB servers.
    monitor             : Manage the Azure Monitor Service.
    mysql               : Manage Azure Database for MySQL servers.
    netappfiles         : Manage Azure NetApp Files (ANF) Resources.
    network             : Manage Azure Network resources.
    policy              : Manage resource policies.
    postgres            : Manage Azure Database for PostgreSQL servers.
    ppg                 : Manage Proximity Placement Groups.
    private-link        : Private-link association CLI command group.
    provider            : Manage resource providers.
    redis               : Manage dedicated Redis caches for your Azure applications.
    relay               : Manage Azure Relay Service namespaces, WCF relays, hybrid connections, and
                         rules.
    reservations        : Manage Azure Reservations.
    resource            : Manage Azure resources.
    resourcemanagement  : Resourcemanagement CLI command group.
    rest                : Invoke a custom request.
    restore-point       : Manage restore point with res.
    role                : Manage user roles for access control with Azure Active Directory and
                         service principals.
    search              : Manage Azure Search services, admin keys and query keys.
    security            : Manage your security posture with Microsoft Defender for Cloud.
    servicebus          : Manage Azure Service Bus namespaces, queues, topics, subscriptions, rules
                         and geo-disaster recovery configuration alias.
    sf                  : Manage and administer Azure Service Fabric clusters.
    sig                 : Manage shared image gallery.
    signalr             : Manage Azure SignalR Service.
    snapshot            : Manage point-in-time copies of managed disks, native blobs, or other
                         snapshots.
    sql                 : Manage Azure SQL Databases and Data Warehouses.
    sshkey              : Manage ssh public key with vm.
    staticwebapp        : Manage static apps.
    storage             : Manage Azure Cloud Storage resources.
    synapse             : Manage and operate Synapse Workspace, Spark Pool, SQL Pool.
    tag                 : Tag Management on a resource.
    term                : Manage marketplace agreement with marketplaceordering.
    ts                  : Manage template specs at subscription or resource group scope.
    upgrade             : Upgrade Azure CLI and extensions.
    version             : Show the versions of Azure CLI modules and extensions in JSON format by
                         default or format configured by --output.
    vm                  : Manage Linux or Windows virtual machines.
    vmss                : Manage groupings of virtual machines in an Azure Virtual Machine Scale Set
                         (VMSS).
    webapp              : Manage web apps.

しかし azコマンドは本物なので、接続先がデフォルトで Azureになっています。
これでは Azuriteを使いませんので、AZURE_STORAGE_CONNECTION_STRING 環境変数を設定します。
サブロウ家の Ubuntu Serverの IPアドレスは 192.168.1.150 ですので適宜読み替えて下さい。
Bashを前提とします。

subro@Ubuntu2204:~$ export AZURE_STORAGE_CONNECTION_STRING="DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://192.168.1.150:10000/devstoreaccount1;QueueEndpoint=http://192.168.1.150:10001/devstoreaccount1;TableEndpoint=http://192.168.1.150:10002/devstoreaccount1;"

ここからは Azureの Blob Storage / Queue Storage / Table Storage それぞれの知識が必要になりますが、そちらは Azuriteを使ってお勉強して頂くことですので、ここでは端折ってドンドン行きます。

「subrocontainer」という名前のストレージコンテナを作ってみましょう。

subro@Ubuntu2204:~$ az storage container create --name subrocontainer
{
  "created": true
}

ストレージコンテナができました。

コンテナのリストを取ってみましょう。

subro@Ubuntu2204:~$ az storage container list
[
  {
    "deleted": null,
    "encryptionScope": null,
    "immutableStorageWithVersioningEnabled": null,
    "metadata": null,
    "name": "subrocontainer",
    "properties": {
      "etag": "\"0x1B15950B359BB40\"",
      "hasImmutabilityPolicy": false,
      "hasLegalHold": false,
      "lastModified": "2022-06-02T05:32:05+00:00",
      "lease": {
        "duration": null,
        "state": "available",
        "status": "unlocked"
      },
      "publicAccess": null
    },
    "version": null
  }
]

subrocontainer が出来ていることが分かります。

コンテナにファイルを入れてみましょう。(これがBlobと呼ばれるのですかね)
「test.txt」ファイルを適当に作って、「test.txt.blob」という Blobになるようアップロードしてみます。

subro@Ubuntu2204:~$ echo "TEST" > text.txt

subro@Ubuntu2204:~$ az storage blob upload --container-name subrocontainer --name test.txt.blob --file test.txt
Finished[#############################################################]  100.0000%
{
  "client_request_id": "fae60806-e237-11ec-97cc-8508fe818a98",
  "content_md5": "Lev9z3nwPkplpmfSHvneFA==",
  "date": "2022-06-02T05:51:00+00:00",
  "encryption_key_sha256": null,
  "encryption_scope": null,
  "etag": "\"0x1A9887C853091B0\"",
  "lastModified": "2022-06-02T05:51:00+00:00",
  "request_id": "f948fd80-979c-4b08-a6ab-a8efe26ffa08",
  "request_server_encrypted": true,
  "version": "2021-06-08",
  "version_id": null
}

アップロードできました。

「subrocontainer」にある Blobの情報を取ってみます。

subro@Ubuntu2204:~$ az storage blob list --container-name subrocontainer
[
  {
    "container": "subrocontainer",
    "content": "",
    "deleted": null,
    "encryptedMetadata": null,
    "encryptionKeySha256": null,
    "encryptionScope": null,
    "hasLegalHold": null,
    "hasVersionsOnly": null,
    "immutabilityPolicy": {
      "expiryTime": null,
      "policyMode": null
    },
    "isAppendBlobSealed": null,
    "isCurrentVersion": null,
    "lastAccessedOn": null,
    "metadata": {},
    "name": "test.txt.blob",
    "objectReplicationDestinationPolicy": null,
    "objectReplicationSourceProperties": null,
    "properties": {
      "appendBlobCommittedBlockCount": null,
      "blobTier": "Hot",
      "blobTierChangeTime": "2022-06-02T05:51:00+00:00",
      "blobTierInferred": true,
      "blobType": "BlockBlob",
      "contentLength": 5,
      "contentRange": null,
      "contentSettings": {
        "cacheControl": null,
        "contentDisposition": null,
        "contentEncoding": null,
        "contentLanguage": null,
        "contentMd5": "Lev9z3nwPkplpmfSHvneFA==",
        "contentType": "text/plain"
      },
      "copy": {
        "completionTime": null,
        "destinationSnapshot": null,
        "id": null,
        "incrementalCopy": null,
        "progress": null,
        "source": null,
        "status": null,
        "statusDescription": null
      },
      "creationTime": "2022-06-02T05:51:00+00:00",
      "deletedTime": null,
      "etag": "0x1A9887C853091B0",
      "lastModified": "2022-06-02T05:51:00+00:00",
      "lease": {
        "duration": null,
        "state": "available",
        "status": "unlocked"
      },
      "pageBlobSequenceNumber": null,
      "pageRanges": null,
      "rehydrationStatus": null,
      "remainingRetentionDays": null,
      "serverEncrypted": true
    },
    "rehydratePriority": null,
    "requestServerEncrypted": null,
    "snapshot": null,
    "tagCount": null,
    "tags": null,
    "versionId": null
  }
]

できていますね。

オマケで、NoSQL Databaseの Table Storageの使用例です。
確か CosmosDBとインターフェイスは同じだったような…。

subro@Ubuntu2204:~$ az storage table create --name subrotable
{
  "created": true
}

subro@Ubuntu2204:~$ az storage table list
[
  {
    "name": "subrotable"
  }
]

subro@Ubuntu2204:~$ az storage entity insert --table-name subrotable --entity {partitionkey="001",rowkey="001",name="subro"}
{
  "date": "2022-06-02T06:40:43+00:00",
  "etag": "W/\"datetime'2022-06-02T06%3A40%3A43.891921Z'\"",
  "version": "2021-06-08"
}

subro@Ubuntu2204:~$ az storage entity query --table-name subrotable
{
  "items": [
    {
      "PartitionKey": "001",
      "RowKey": "001",
      "Timestamp": "2022-06-02T06:40:43.891000+00:00",
      "etag": "W/\"datetime'2022-06-02T06%3A40%3A43.891921Z'\"",
      "name": "subro"
    }
  ],
  "nextMarker": {}
}

これ以上やると Azureの練習になってしまいますのでここで止めておきます。

マイクロソフトは Blob/Queue/Table用のAPIを Powershell・C#・Python・JavaScript・Javaなどに出していたと思いますので、プログラムから使ってみるのも面白いと思います。

Azuriteはマイクロソフトも認識しているもので、確かメンテナーにもマイクロソフトの人が入っていた気がします。
ただそれでも完全無欠のものではなく「なるべく似せている」ものであることはドキュメントにも書いてありました。
ですので Azuriteを使ってテストをしたものについては、必ずAzureでもテストをして下さい。



Azureの本って前から少ないんですよね…。

全体像と用語がよくわかる!Microsoft Azure入門ガイド [ 山田裕進 ]

価格:3,102円
(2022/6/2 15:25時点)
感想(0件)