Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Azure Cosmos DB + Functions Cookbook - Multi master & preferred region
public static async Task<HttpResponseMessage> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,
[CosmosDB(databaseName: "%CosmosDBDatabase%",
collectionName: "%CosmosDBCollection%",
ConnectionStringSetting = "CosmosDBConnectionString",
UseMultipleWriteLocations = true,
PreferredLocations = "Central US"
)] IAsyncCollector<MyClass> documentsToSave,
ILogger log)
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
MyClass[] inputDocuments = JsonConvert.DeserializeObject<MyClass[]>(requestBody);
if (inputDocuments == null)
return new HttpResponseMessage(HttpStatusCode.BadRequest);
foreach (MyClass inputDocument in inputDocuments)
await documentsToSave.AddAsync(inputDocument);
return new HttpResponseMessage(HttpStatusCode.Created);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.