azure-resource-manager-cosmosdb-dotnet – skill DevOps & Hạ tầng cho agent AI
SDK Azure Resource Manager cho Cosmos DB trên .NET.
Cài skill azure-resource-manager-cosmosdb-dotnet bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/azure-resource-manager-cosmosdb-dotnet-119d2.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /azure-resource-manager-cosmosdb-dotnet – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/azure-resource-manager-cosmosdb-dotnet-119d2.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $azure-resource-manager-cosmosdb-dotnet – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/azure-resource-manager-cosmosdb-dotnet-119d2.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /azure-resource-manager-cosmosdb-dotnet – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/azure-resource-manager-cosmosdb-dotnet-119d2.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /azure-resource-manager-cosmosdb-dotnet – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc bằng tiếng Anh.
Bundled upstream support
Supporting files are included at skill-relative paths. See [UPSTREAM-NOTICE.md](UPSTREAM-NOTICE.md) for their pinned sources, licenses, hashes, and import changes.
Azure.ResourceManager.CosmosDB (.NET)
Management plane SDK for provisioning and managing Azure Cosmos DB resources via Azure Resource Manager.
> ⚠️ Management vs Data Plane
> - This SDK (Azure.ResourceManager.CosmosDB): Create accounts, databases, containers, configure throughput, manage RBAC
> - Data Plane SDK (Microsoft.Azure.Cosmos): CRUD operations on documents, queries, stored procedures execution
Installation
dotnet add package Azure.ResourceManager.CosmosDB
dotnet add package Azure.IdentityVersion scope: Imported examples are historical and are not a current-version declaration; pin and compile against the intended SDK. Required common imports include Azure, Azure.Core and Azure.ResourceManager.Resources.
Environment Variables
AZURE_SUBSCRIPTION_ID=<your-subscription-id>
# For service principal auth (optional)
AZURE_TENANT_ID=<tenant-id>
AZURE_CLIENT_ID=<client-id>
AZURE_CLIENT_SECRET=<client-secret>Authentication
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.CosmosDB;
// Choose the intended tenant/identity explicitly; DefaultAzureCredential is convenient for local development.
var credential = new DefaultAzureCredential();
var armClient = new ArmClient(credential);
// Get subscription
var subscriptionId = Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID");
var subscription = armClient.GetSubscriptionResource(
new ResourceIdentifier($"/subscriptions/{subscriptionId}"));Resource Hierarchy
ArmClient
└── SubscriptionResource
└── ResourceGroupResource
└── CosmosDBAccountResource
├── CosmosDBSqlDatabaseResource
│ └── CosmosDBSqlContainerResource
│ ├── CosmosDBSqlStoredProcedureResource
│ ├── CosmosDBSqlTriggerResource
│ └── CosmosDBSqlUserDefinedFunctionResource
├── CassandraKeyspaceResource
├── GremlinDatabaseResource
├── MongoDBDatabaseResource
└── CosmosDBTableResourceConfirm subscription, tenant, region, exact resources, budget and network/retention policy before provisioning. Deletion/failover/rotation require explicit authorization; ARM RBAC and data-plane RBAC are separate.
Core Workflow
1. Create Cosmos DB Account
using Azure.ResourceManager.CosmosDB;
using Azure.ResourceManager.CosmosDB.Models;
// Get resource group
var resourceGroup = await subscription
.GetResourceGroupAsync("my-resource-group");
// Define account
var accountData = new CosmosDBAccountCreateOrUpdateContent(
location: AzureLocation.EastUS,
locations: new[]
{
new CosmosDBAccountLocation
{
LocationName = AzureLocation.EastUS,
FailoverPriority = 0,
IsZoneRedundant = false
}
})
{
Kind = CosmosDBAccountKind.GlobalDocumentDB,
ConsistencyPolicy = new ConsistencyPolicy(DefaultConsistencyLevel.Session),
EnableAutomaticFailover = true
};
// Create account (long-running operation)
var accountCollection = resourceGroup.Value.GetCosmosDBAccounts();
var operation = await accountCollection.CreateOrUpdateAsync(
WaitUntil.Completed,
"my-cosmos-account",
accountData);
CosmosDBAccountResource account = operation.Value;2. Create SQL Database
var databaseData = new CosmosDBSqlDatabaseCreateOrUpdateContent(
new CosmosDBSqlDatabaseResourceInfo("my-database"));
var databaseCollection = account.GetCosmosDBSqlDatabases();
var dbOperation = await databaseCollection.CreateOrUpdateAsync(
WaitUntil.Completed,
"my-database",
databaseData);
CosmosDBSqlDatabaseResource database = dbOperation.Value;3. Create SQL Container
var containerData = new CosmosDBSqlContainerCreateOrUpdateContent(
new CosmosDBSqlContainerResourceInfo("my-container")
{
PartitionKey = new CosmosDBContainerPartitionKey
{
Paths = { "/partitionKey" },
Kind = CosmosDBPartitionKind.Hash
},
IndexingPolicy = new CosmosDBIndexingPolicy
{
Automatic = true,
IndexingMode = CosmosDBIndexingMode.Consistent
},
DefaultTtl = 86400 // 24 hours
});
var containerCollection = database.GetCosmosDBSqlContainers();
var containerOperation = await containerCollection.CreateOrUpdateAsync(
WaitUntil.Completed,
"my-container",
containerData);
CosmosDBSqlContainerResource container = containerOperation.Value;4. Configure Throughput
// Manual throughput
var throughputData = new ThroughputSettingsUpdateData(
new ThroughputSettingsResourceInfo
{
Throughput = 400
});
// Autoscale throughput
var autoscaleData = new ThroughputSettingsUpdateData(
new ThroughputSettingsResourceInfo
{
AutoscaleSettings = new AutoscaleSettingsResourceInfo
{
MaxThroughput = 4000
}
});
// Apply to database
await database.CreateOrUpdateCosmosDBSqlDatabaseThroughputAsync(
WaitUntil.Completed,
throughputData);5. Get Connection Information
// Get keys
var keys = await account.GetKeysAsync();
// Pass the key directly to an approved secret store; never print it.
// Get connection strings
var connectionStrings = await account.GetConnectionStringsAsync();
foreach (var cs in connectionStrings.Value.ConnectionStrings)
{
Console.WriteLine($"Connection available: {cs.Description} (value redacted)");
}Key Types Reference
| Type | Purpose |
|------|---------|
| ArmClient | Entry point for all ARM operations |
| CosmosDBAccountResource | Represents a Cosmos DB account |
| CosmosDBAccountCollection | Collection for account CRUD |
| CosmosDBSqlDatabaseResource | SQL API database |
| CosmosDBSqlContainerResource | SQL API container |
| CosmosDBAccountCreateOrUpdateContent | Account creation payload |
| CosmosDBSqlDatabaseCreateOrUpdateContent | Database creation payload |
| CosmosDBSqlContainerCreateOrUpdateContent | Container creation payload |
| ThroughputSettingsUpdateData | Throughput configuration |
Best Practices
1. Use WaitUntil.Completed for operations that must finish before proceeding
2. Use WaitUntil.Started when you want to poll manually or run operations in parallel
3. Use a deliberate credential chain — prefer managed identity in production; never hardcode keys
4. Handle RequestFailedException for ARM API errors
5. Review the full desired state before CreateOrUpdateAsync — repeated requests may converge but updates can change networking, retention and cost
6. Navigate hierarchy via Get* methods (e.g., account.GetCosmosDBSqlDatabases())
Error Handling
using Azure;
try
{
var operation = await accountCollection.CreateOrUpdateAsync(
WaitUntil.Completed, accountName, accountData);
}
catch (RequestFailedException ex) when (ex.Status == 409)
{
Console.WriteLine("Conflict: inspect the error code and current resource; 409 does not prove the requested account already exists");
}
catch (RequestFailedException ex)
{
Console.WriteLine($"ARM Error: {ex.Status} - {ex.ErrorCode}");
}Reference Files
| File | When to Read |
|------|--------------|
| references/account-management.md | Account CRUD, failover, keys, connection strings, networking |
| references/sql-resources.md | SQL databases, containers, stored procedures, triggers, UDFs |
| references/throughput.md | Manual/autoscale throughput, migration between modes |
Related SDKs
| SDK | Purpose | Install |
|-----|---------|---------|
| Microsoft.Azure.Cosmos | Data plane (document CRUD, queries) | dotnet add package Microsoft.Azure.Cosmos |
| Azure.ResourceManager.CosmosDB | Management plane (this SDK) | dotnet add package Azure.ResourceManager.CosmosDB |
When to Use
This skill is applicable to execute the workflow or actions described in the overview.
Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
Skill liên quan
- azure-resource-manager-durabletask-dotnet – SDK Azure Resource Manager cho Durable Task Scheduler trên .NET.
- azure-resource-manager-mysql-dotnet – SDK Azure MySQL Flexible Server cho .NET. Quản lý cơ sở dữ liệu cho các triển khai MySQL…
- azure-resource-manager-playwright-dotnet – SDK Azure Resource Manager cho Microsoft Playwright Testing trên .NET.
- azure-resource-manager-redis-dotnet – SDK Azure Resource Manager cho Redis trên .NET.
- azure-resource-manager-sql-dotnet – SDK Azure Resource Manager cho Azure SQL trên .NET.
- azure-search-documents-dotnet – SDK Azure AI Search cho .NET (Azure.Search.Documents). Dùng để xây dựng ứng dụng tìm…
- azure-search-documents-py – SDK Azure AI Search cho Python. Dùng cho tìm kiếm vector, tìm kiếm hybrid, xếp hạng ngữ…
- azure-search-documents-ts – Xây dựng ứng dụng tìm kiếm với khả năng tìm kiếm vector, hybrid và ngữ nghĩa (semantic).