Skip to content

Commit

Permalink
Cosmos DBトリガーを試す
Browse files Browse the repository at this point in the history
  • Loading branch information
backpaper0 committed Sep 7, 2024
1 parent 19f92cf commit fb13448
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
6 changes: 6 additions & 0 deletions azure/python-function-example/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
cosmos:
image: mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator
ports:
- "8081:8081"
- "10250-10255:10250-10255"
18 changes: 16 additions & 2 deletions azure/python-function-example/function_app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import datetime
import json
import logging

import azure.functions as func
Expand Down Expand Up @@ -29,3 +27,19 @@ def HttpExample(req: func.HttpRequest) -> func.HttpResponse:
"This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
status_code=200,
)


@app.function_name(name="CosmosDBTrigger")
@app.cosmos_db_trigger(
arg_name="documents",
connection="CosmosDBConnectionString",
database_name="example_db",
container_name="example_container",
create_lease_container_if_not_exists=True,
)
def test_function(documents: func.DocumentList) -> None:
if documents:
for index, doc in enumerate(documents):
logging.info(f"{index} Document: {dict(doc)}")
else:
logging.info("No documents found")

0 comments on commit fb13448

Please sign in to comment.