Skip to content

Commit 78f2406

Browse files
author
Yoichi Kawasaki
committed
Added http-trigger-dump-request
1 parent 304cdb3 commit 78f2406

File tree

4 files changed

+192
-0
lines changed

4 files changed

+192
-0
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ This is a collection of Python function samples on Azure Functions 2.X. For a co
2424
| [queue-trigger-blob-in-out-binding](v2functions/queue-trigger-blob-in-out-binding) | Azure Functions Queue Trigger Python Sample. The function gets a file name from queue message, reads a blob file named the file name using Blob Input Binding, then ROT13 encodes the obtained clear text, and finally stores it into Azure Blob Storage using Blob Output Binding | Queue Storage | Blob Storage | Blob Storage |
2525
| [timer-trigger-cosmos-output-binding](v2functions/timer-trigger-cosmosdb-output-binding) | Azure Functions Timer Trigger Python Sample. The function gets blog RSS feed and store the results into CosmosDB using Cosmos DB output binding | Timer | NONE | CosmosDB |
2626
| [http-trigger-blob-sas-token](v2functions/http-trigger-blob-sas-token) | Azure Function HTTP Trigger Python Sample that returns a SAS token for Azure Storage for the specified container and blob name | HTTP | NONE | HTTP |
27+
| [http-trigger-dump-request](v2functions/http-trigger-dump-request) | Azure Function HTTP Trigger Python Sample that returns request dump info with JSON format | HTTP | NONE | HTTP |
2728
| [blob-trigger-watermark-blob-out-binding](v2functions/blob-trigger-watermark-blob-out-binding) | Azure Function Python Sample that watermarks an image. This function triggers on an input blob (image) and adds a watermark by calling into the Pillow library. The resulting composite image is then written back to blob storage using a blob output binding. | Blob Storage | Blob Storage | Blob Storage |
2829

2930
### Documents
3031
* [Quickstart V2 Python Functions with Azure Functions Core Tools](docs/quickstart-v2-python-functions.md)
32+
* [Quickstart Function Samples as a Custom image with Docker](docs/quickstart-samples-custom-image-with-docker.md)
3133
* [Azure Functions Python developer guide](https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-python)
3234
* [Zip push deployment for Azure Functions](https://docs.microsoft.com/en-us/azure/azure-functions/deployment-zip-push)
3335
* [Work with Azure Functions Proxies](https://docs.microsoft.com/en-us/azure/azure-functions/functions-proxies)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Quickstart Function Samples as a Custom image with Docker
2+
3+
This is a quickstart on how you start running Python function samples as a custom image (Container) with Docker.
4+
5+
<!-- TOC -->
6+
- [Quickstart Function Samples as a Custom image with Docker](#quickstart-function-samples-as-a-custom-image-with-docker)
7+
- [Prerequisites](#prerequisites)
8+
- [Git clone source code](#git-clone-source-code)
9+
- [Create Azure Resources that required to run the samples](#create-azure-resources-that-required-to-run-the-samples)
10+
- [[Required] Azure Storage Account](#required-azure-storage-account)
11+
- [[Optional] CosmosDB and Computer Vision API](#optional-cosmosdb-and-computer-vision-api)
12+
- [Build Container Image](#build-container-image)
13+
- [Run the image locally](#run-the-image-locally)
14+
- [1. Run the image with minimum configuration](#1-run-the-image-with-minimum-configuration)
15+
- [2. Run the image with full configuration](#2-run-the-image-with-full-configuration)
16+
- [Test access to the functions](#test-access-to-the-functions)
17+
- [LINKS](#links)
18+
19+
20+
## Prerequisites
21+
- [Docker](https://docs.docker.com/)
22+
23+
## Git clone source code
24+
```sh
25+
git clone https://github.com/yokawasa/azure-functions-python-samples.git
26+
```
27+
28+
## Create Azure Resources that required to run the samples
29+
30+
This project include a set of multiple sample function and each function may have different required resources. Please check `readme.md` included in each function sample (Check [v2functions](../v2functions)).
31+
32+
### [Required] Azure Storage Account
33+
A minimum is an `Azure Storage Account` which is necessary for all functions. Here is how you create:
34+
35+
> [scripts/create-resource-group.sh](../scripts/create-resource-group.sh)
36+
```bash
37+
RESOURCE_GROUP="<RESOURCE GROUPP MAME>"
38+
REGION="<REGION NAME: eastus>"
39+
az group create --name $RESOURCE_GROUP --location $REGION
40+
```
41+
> [scripts/create-storage-account.sh](../scripts/create-storage-account.sh)
42+
```bash
43+
RESOURCE_GROUP="<RESOURCE GROUPP MAME>"
44+
REGION="<REGION NAME: eastus>"
45+
STORAGE_ACCOUNT="<STORAGE ACCOUNT NAME>"
46+
47+
echo "Create an Azure Storage account: $STORAGE_ACCOUNT"
48+
az storage account create --name $STORAGE_ACCOUNT \
49+
--location $REGION \
50+
--resource-group $RESOURCE_GROUP \
51+
--sku Standard_LRS
52+
```
53+
54+
### [Optional] CosmosDB and Computer Vision API
55+
The rest of resources such as Cosmos DB account and Computer Vision Subscription are optionals:
56+
57+
For CosmosDB Account and its database and collections, you can leverage the following helper script. Adding required params in the script and running will create a CosmosDB Account and database and collections.
58+
> [scripts/create-cosmosdb-test-db-coll.sh](../scripts/create-cosmosdb-test-db-coll.sh)
59+
60+
For Computer Vision API subscription, you can leverage the following helper script. Likewise, add required params in the script and run it.
61+
> [scripts/create-cognitive-computer-vision.sh](../scripts/create-cognitive-computer-vision.sh)
62+
63+
## Build Container Image
64+
65+
Let's build the image from the Docker file using `docker build` command.
66+
67+
```bash
68+
cd v2functions
69+
70+
# Build the image with `docker build` command
71+
# docker build --tag <docker-id>/<imagename>:<tag> .
72+
docker build --tag yoichikawasaki/azfuncpythonsamples:v0.0.1 .
73+
```
74+
You can also use a helper script - [scripts/docker-build.sh](../scripts/docker-build.sh)
75+
76+
## Run the image locally
77+
78+
Now you're ready to run the app. You have 2 options
79+
80+
### 1. Run the image with minimum configuration
81+
82+
> [scripts/docker-run-mini.sh](../scripts/docker-run-mini.sh)
83+
```bash
84+
...
85+
docker run -p 8080:80 -it \
86+
-e AzureWebJobsStorage="$STORAGE_CONNECTION_STRING" \
87+
$DOCKER_ID/$CONTAINER_IMAGE_NAME:$TAG
88+
...
89+
```
90+
91+
### 2. Run the image with full configuration
92+
93+
> [scripts/docker-run.sh](../scripts/docker-run.sh)
94+
```bash
95+
...
96+
docker run -p 8080:80 -it \
97+
-e AzureWebJobsStorage="$STORAGE_CONNECTION_STRING" \
98+
-e MyStorageConnectionString="$STORAGE_CONNECTION_STRING" \
99+
-e MyCosmosDBConnectionString="$COSMOSDB_CONNECTION_STRING" \
100+
-e ComputerVisionSubscription="$COMPUTER_VSION_API_SUBSCRIPTION" \
101+
-e ComputerVisionApiEndpoint="$COMPUTER_VSION_API_ENDPOINT" \
102+
$DOCKER_ID/$CONTAINER_IMAGE_NAME:$TAG
103+
...
104+
```
105+
106+
## Test access to the functions
107+
108+
Once you start the app with docker, let's send a test request to `http-trigger-dump-request` function:
109+
110+
```bash
111+
curl -s http://localhost:8080/api/http-trigger-dump-request |jq
112+
113+
{
114+
"method": "GET",
115+
"url": "http://localhost:8080/api/http-trigger-dump-request",
116+
"headers": {
117+
"accept": "*/*",
118+
"host": "localhost:8080",
119+
"user-agent": "curl/7.54.0"
120+
},
121+
"params": {},
122+
"get_body": ""
123+
}
124+
125+
```
126+
127+
## LINKS
128+
- [Create a function on Linux using a custom image](https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-function-linux-custom-image)

scripts/send-test-blob-sas-token.sh

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/sh
2+
3+
# api_url="AZURE_FUNCTION_ENDPOINT: ex. https://<app_account>.azurewebsites.net/api/<func_name>"
4+
# api_key="AZURE_FUNCTION_KEY: ex. aRVQ7Lj0vzDhY0JBYF8gpxYyEBxLwhO51JSC7X5dZFbTvROs7xNg=="
5+
6+
# func locally
7+
api_url="http://localhost:7071/api/http-trigger-blob-sas-token"
8+
# Docker
9+
# api_url="http://localhost:8080/api/http-trigger-blob-sas-token"
10+
api_key=""
11+
12+
echo "Sending HTTP POST Request............."
13+
curl -s\
14+
-H "Content-Type: application/json; charset=UTF-8"\
15+
-H "x-functions-key: ${api_key}"\
16+
-XPOST ${api_url} -d'{
17+
"permission": "rl",
18+
"container": "functiontest",
19+
"blobname": "sample.jpg",
20+
"ttl": 2
21+
}'
22+
echo ""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# http-trigger-blob-sas-token (Python)
2+
3+
- [http-trigger-blob-sas-token (Python)](#http-trigger-blob-sas-token-python)
4+
- [Local development](#local-development)
5+
- [Test acccess](#test-acccess)
6+
- [Publish the function to the cloud](#publish-the-function-to-the-cloud)
7+
8+
| Sample | Description | Trigger | In Bindings | Out Bindings
9+
| ------------- | ------------- | ------------- | ----------- | ----------- |
10+
| [http-trigger-dump-request](v2functions/http-trigger-dump-request) | Azure Function HTTP Trigger Python Sample that returns request dump info with JSON format | HTTP | NONE | HTTP |
11+
12+
13+
## Local development
14+
```sh
15+
func host start
16+
```
17+
18+
## Test acccess
19+
```sh
20+
curl -s http://localhost:7071/api/http-trigger-dump-request |jq
21+
{
22+
"method": "GET",
23+
"url": "http://localhost:7071/api/http-trigger-dump-request",
24+
"headers": {
25+
"accept": "*/*",
26+
"host": "localhost:8080",
27+
"user-agent": "curl/7.54.0"
28+
},
29+
"params": {},
30+
"get_body": ""
31+
}
32+
```
33+
34+
## Publish the function to the cloud
35+
36+
Publish the function to the cloud
37+
```sh
38+
FUNCTION_APP_NAME="MyFunctionApp"
39+
func azure functionapp publish $FUNCTION_APP_NAME
40+
```

0 commit comments

Comments
 (0)