Skip to content

Latest commit

 

History

History
134 lines (90 loc) · 3.34 KB

File metadata and controls

134 lines (90 loc) · 3.34 KB

Deploy a Cosmos DB output Function

functionapp/cosmosdb-output/README.md

Prerequisites

This example assumes you have previously completed the following examples:

  1. Create an Azure Resource Group
  2. Install Azure Functions Core Tools
  3. Create an Azure Cosmos DB

Set the Java function name environment variable

  export FUNCTIONS_COSMOSDB=functions-cosmosdb-$RANDOM

Set the Cosmos DB connection string environment variable

  export FUNCTIONS_COSMOSDB_CONNECTION_STRING="$(az cosmosdb keys list --resource-group $RESOURCE_GROUP --name $COSMOSDB_ACCOUNT_NAME --type connection-strings --query connectionStrings[0].connectionString --output tsv)"

Setup the local environment

  mvn -P local validate

Build the example

To build the JAR file use the following Maven command line.

  mvn -DresourceGroup=$RESOURCE_GROUP \
      -DappName=$FUNCTIONS_COSMOSDB \
      -Dregion=$REGION \
      package

Run the example locally

To run the example locally use the following Maven command line.

  mvn -DappName=$FUNCTIONS_COSMOSDB \
      -Dregion=$REGION \
      -DresourceGroup=$RESOURCE_GROUP \
      clean package azure-functions:run

You can verify the function works by using your browser and going to http://localhost:7071/api/cosmosDBOutput

You should see We stored an item in Cosmos DB in your brower.

Deploy the example to Azure

  mvn -DappName=$FUNCTIONS_COSMOSDB \
      -Dregion=$REGION \
      -DresourceGroup=$RESOURCE_GROUP \
      -DcosmosDBConnectionString="$FUNCTIONS_COSMOSDB_CONNECTION_STRING" \
      clean package azure-functions:deploy

To verify the function works open your browser to the URL echoed by the following command line:

  echo `az functionapp show \
    --resource-group $RESOURCE_GROUP \
    --name $FUNCTIONS_COSMOSDB \
    --query hostNames \
    --output tsv`/api/cosmosDBOutput

You should see We stored an item in Cosmos DB in your browser.

Cleanup

Do NOT forget to remove the resources once you are done running the example.

Next steps

5m