Set up Azure Cosmos DB
✓Works with OpenClaudeYou are an Azure cloud infrastructure engineer. The user wants to set up Azure Cosmos DB with proper configuration, connection, and data initialization.
What to check first
- Run
az account showto verify you're authenticated to the correct Azure subscription - Run
az cosmosdb list --output tableto see if a Cosmos DB account already exists - Verify the Azure CLI is installed:
az --version
Steps
- Create a resource group with
az group create --name myResourceGroup --location eastus - Create a Cosmos DB account using
az cosmosdb create --resource-group myResourceGroup --name mycosmosdb --kind GlobalDocumentDB(this takes 5-10 minutes) - Get the primary connection string:
az cosmosdb keys list --resource-group myResourceGroup --name mycosmosdb --type connection-strings --query connectionStrings[0].connectionString - Create a database within the account using
az cosmosdb sql database create --resource-group myResourceGroup --account-name mycosmosdb --name myDatabase - Create a container (collection) with
az cosmosdb sql container create --resource-group myResourceGroup --account-name mycosmosdb --database-name myDatabase --name myContainer --partition-key-path "/id" - Set throughput (RUs) for the container:
az cosmosdb sql container throughput update --resource-group myResourceGroup --account-name mycosmosdb --database-name myDatabase --name myContainer --throughput 400 - Store the connection string as an environment variable for your application to consume
- Test connectivity by initializing a client connection and performing a read operation
Code
import os
from azure.cosmos import CosmosClient, PartitionKey
# Retrieve connection string from environment or Azure Key Vault
connection_string = os.getenv("COSMOS_CONNECTION_STRING")
database_name = "myDatabase"
container_name = "myContainer"
# Initialize Cosmos DB client
client = CosmosClient.from_connection_string(connection_string)
# Get or create database
database = client.create_database_if_not_exists(id=database_name)
print(f"Database '{database_name}' ready")
# Get or create container with partition key
container = database.create_container_if_not_exists(
id=container_name,
partition_key=PartitionKey(path="/id"),
offer_throughput=400
)
print(f"Container '{container_name}' ready")
# Insert sample document
sample_item = {
"id": "item-001",
"name": "Sample Item",
"category": "example",
"price": 29.99
}
created_item = container.create_item(body=sample_item)
print(f"Inserted document: {created_item['id']}")
# Query documents
query = "SELECT * FROM c WHERE c.category = @category"
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Cloud (AWS/GCP/Azure) Skills
Other Claude Code skills in the same category — free to download.
Lambda Function
Create AWS Lambda function with handler
S3 Operations
Set up S3 bucket operations (upload, download, presigned URLs)
DynamoDB CRUD
Create DynamoDB CRUD operations
SQS Setup
Set up SQS queue producer and consumer
SNS Notifications
Configure SNS for push notifications
CloudFront Setup
Set up CloudFront CDN distribution
Cognito Auth
Implement AWS Cognito authentication
RDS Setup
Configure RDS database connection
Want a Cloud (AWS/GCP/Azure) skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.