本記事では、Azure Cosmos DBにAzure App Serviceから読み書きする際のロール付与方法を記載します。
前提
- Azureアカウントを持っていること
- Azure App ServiceとAzure Cosmos DBがすでに構築されていること
- Azure CLIがインストールされており、Azureにログインしていること
手順
- Azure App Serviceの設定->IDから、システム割り当てマネージドIDを有効にし、プリンシパルIDをメモする。
- Azure CLIから、以下のコマンドを実行し、Cosmos DB組み込みデータ共同作成者ロールを割り当てる。
az cosmosdb sql role assignment create --account-name <Cosmos DB アカウント名> --resource-group <Cosmos DB アカウントが属するリソースグループ名> --scope "/" --principal-id <マネージド ID のプリンシパル ID> --role-definition-id "00000000-0000-0000-0000-000000000002"
以上です。