|
4 | 4 | | ------------- | ------------- | ------------- | ----------- | ----------- |
|
5 | 5 | | `cosmosdb-trigger-cosmosdb-in-binding` | Azure Functions Blob Storage Trigger Python Sample. The function gets image data from Azure Blob Trigger, gets tags for the image with [Computer Vision API](https://azure.microsoft.com/en-us/services/cognitive-services/computer-vision/) ([Azure Cognitive Services](https://azure.microsoft.com/en-us/services/cognitive-services/)), and store the tags into Azure Cosmos DB by leveraging CosmosDB output binding | Blob Storage | NONE | CosmosDB |
|
6 | 6 |
|
| 7 | +<!-- TOC --> |
| 8 | +- [blob-trigger-cosmosdb-out-binding (Python)](#blob-trigger-cosmosdb-out-binding-python) |
| 9 | + - [Configurations](#configurations) |
| 10 | + - [Create Computer Vision resource](#create-computer-vision-resource) |
| 11 | + - [Create Blob Storage account & Container](#create-blob-storage-account--container) |
| 12 | + - [Create Cosmos DB Account and DB & Collection](#create-cosmos-db-account-and-db--collection) |
| 13 | + - [How to develop and publish the function](#how-to-develop-and-publish-the-function) |
| 14 | + - [Local development](#local-development) |
| 15 | + - [Publish the function to the cloud](#publish-the-function-to-the-cloud) |
| 16 | + - [Test Request](#test-request) |
| 17 | + - [HTTP Request body format](#http-request-body-format) |
| 18 | + - [Response body format](#response-body-format) |
| 19 | + |
7 | 20 | ## Configurations
|
8 | 21 | As specified in `functions.json`, you need Azure Storage account for triggering functions and Cosmos DB Account to store data using Cosmos DB output binding
|
9 | 22 |
|
@@ -31,12 +44,42 @@ As specified in `functions.json`, you need Azure Storage account for triggering
|
31 | 44 | }
|
32 | 45 | ]
|
33 | 46 | }
|
| 47 | +``` |
| 48 | + |
| 49 | +### Create Computer Vision resource |
| 50 | + |
| 51 | +First, create a Computer Vision resource |
| 52 | + |
| 53 | +```bash |
| 54 | +COGNITIVE_RESOURCE_GROUP="rg_cognitive_test" |
| 55 | +REGION="eastasia" |
| 56 | +COGNITIVE_ACCOUNT_NAME="mycompvision001" |
| 57 | + |
| 58 | +echo "Create Resource Group: $COGNITIVE_RESOURCE_GROUP" |
| 59 | +az group create --name $COGNITIVE_RESOURCE_GROUP --location $REGION |
| 60 | + |
| 61 | +echo "Create Cognitive Resource for Computer Vision: $COGNITIVE_ACCOUNT_NAME" |
| 62 | +az cognitiveservices account create \ |
| 63 | + -n $COGNITIVE_ACCOUNT_NAME \ |
| 64 | + -g $COGNITIVE_RESOURCE_GROUP \ |
| 65 | + --kind ComputerVision \ |
| 66 | + --sku S1 \ |
| 67 | + -l $REGION \ |
| 68 | + --yes |
| 69 | +``` |
34 | 70 |
|
| 71 | +Then, Get Computer Vision API Key and endpoint. You'll use the values in later step: |
| 72 | +```bash |
| 73 | +COMPUTER_VISION_API_ENDPOINT=$(az cognitiveservices account show -n $COGNITIVE_ACCOUNT_NAME -g $COGNITIVE_RESOURCE_GROUP --output tsv |awk '{print $1}') |
| 74 | +COMPUTER_VISION_API_KEY=$(az cognitiveservices account keys list -n $COGNITIVE_ACCOUNT_NAME -g $COGNITIVE_RESOURCE_GROUP --output tsv |awk '{print $1}') |
| 75 | +echo "API Endpoint: $COMPUTER_VISION_API_ENDPOINT" |
| 76 | +echo "API KEY: $COMPUTER_VISION_API_KEY" |
35 | 77 | ```
|
| 78 | + |
36 | 79 | ### Create Blob Storage account & Container
|
37 | 80 |
|
38 | 81 | Create an Azure Storage Account
|
39 |
| -```sh |
| 82 | +```bash |
40 | 83 | RESOURCE_GROUP="rg-testfunctions"
|
41 | 84 | REGION="japaneast"
|
42 | 85 | STORAGE_ACCOUNT="teststore"
|
@@ -127,6 +170,49 @@ az webapp config appsettings set \
|
127 | 170 | -n $FUNCTION_APP_NAME \
|
128 | 171 | -g $RESOURCE_GROUP \
|
129 | 172 | --settings \
|
| 173 | + ComputerVisionSubscription=$COMPUTER_VISION_API_KEY \ |
| 174 | + ComputerVisionApiEndpoint=$COMPUTER_VISION_API_ENDPOINT \ |
130 | 175 | MyStorageConnectionString=$FUNCTION_STORAGE_CONNECTION \
|
131 | 176 | MyCosmosDBConnectionString=$COSMOS_DB_CONNECTION
|
132 | 177 | ```
|
| 178 | + |
| 179 | +## Test Request |
| 180 | + |
| 181 | +### HTTP Request body format |
| 182 | +HTTP Request body must include the following parameters: |
| 183 | +``` |
| 184 | +{ |
| 185 | + 'permission': '<Signed permission for shared access signature (Required)>', |
| 186 | + 'container': '<Container name to access (Required)>', |
| 187 | + 'blobname': '<Blob object name to access (Optional)>' |
| 188 | + 'ttl': '<Token time to live period in hours. 1hour by default (Optional)>' |
| 189 | +} |
| 190 | +``` |
| 191 | + |
| 192 | +The following values can be used for permissions: |
| 193 | +`a` (Add), `r` (Read), `w` (Write), `d` (Delete), `l` (List) |
| 194 | +Concatenate multiple permissions, such as `rwa` = Read, Write, Add |
| 195 | + |
| 196 | +Sample Request Body |
| 197 | +``` |
| 198 | + { |
| 199 | + 'permission': "rl", |
| 200 | + 'container': "functiontest", |
| 201 | + 'blobname': "sample.png" |
| 202 | + 'ttl': 2 |
| 203 | + } |
| 204 | +``` |
| 205 | + |
| 206 | +## Response body format |
| 207 | +HTTP response body format is: |
| 208 | +``` |
| 209 | +{ |
| 210 | + 'token': '<Shared Access Signature Token string>', |
| 211 | + 'url' : '<SAS resource URI>' |
| 212 | +} |
| 213 | +``` |
| 214 | + |
| 215 | +Sample Response Body |
| 216 | +``` |
| 217 | +{'url': 'https://testfunction.blob.core.windows.net/functiontest/yokawasa.png?sig=sXBjML1Fpk9UnTBtajo05ZTFSk0LWFGvARZ6WlVcAog%3D&srt=o&ss=b&spr=https&sp=rl&sv=2016-05-31&se=2017-07-01T00%3A21%3A38Z&st=2017-07-01T23%3A16%3A38Z', 'token': 'sig=sXBjML1Fpk9UnTBtajo05ZTFSk0LWFGvARZ6WlVcAog%3D&srt=o&ss=b&spr=https&sp=rl&sv=2016-05-31&se=2017-07-01T00%3A21%3A38Z&st=2017-07-01T23%3A16%3A38Z'} |
| 218 | +``` |
0 commit comments