0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

背景

Azure Cosmos DB を触ったので、その備忘録

使ったのは、SQLデータベースとして

構成

- Account: [schema](https://learn.microsoft.com/ja-jp/azure/templates/microsoft.documentdb/databaseaccounts?pivots=deployment-language-bicep)
    - Database: [schema](https://learn.microsoft.com/ja-jp/azure/templates/microsoft.documentdb/databaseaccounts/sqldatabases?pivots=deployment-language-bicep)
        - Container: [schema](https://learn.microsoft.com/ja-jp/azure/templates/microsoft.documentdb/databaseaccounts/sqldatabases/containers?pivots=deployment-language-bicep)

Account

  • 最初に Azure Entra かと思ってたが :sweat_smile:、Resource そのものと理解
  • ここで Free Tier の設定や、合計スループット制限が可能
  • Free Tier 使う場合は、Microsoft.DocumentDB/databaseAccounts@2021-10-15 以降
Free Tire 利用
  properties: {
    enableFreeTier: true
    capacity: {
      totalThroughputLimit: 1000
    }

Database

  • 各種DBの種類を選ぶ。今回は、SQLを選択。No SQL に使えるってのが面白い
  • スループット最低は400。Free だと 1000
Free Tier のスループット 1000
resource cosmosDbDatabase 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases@2021-04-15' = {
  parent: cosmosDbAccount
  name: cosmosDbDatabaseName
  properties: {
    resource: {
      id: cosmosDbDatabaseName
    }
    options: {
      throughput: 1000
    }
  }
}

Container

  • 通常は複数 Container を用意する感じ
  • Container に対して、SQL 発行する
  • ってことで、

    CosmosClient().get_database_client().get_container_client()

  • SQL injection 対策用の bind は、parameters で
    image.png

SQL の制限

  • delete は一括で出来ないので、Stored Procedure を使う

azd provision/up

以下のように、更新不可なものもある。

  • container throughput
  • sku

python での制御Samples

あとがき

インフラ苦手意識があるけど、bicep で出来ると分かりやすくていいね :laughing:

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?