Sample | Description | Trigger | In Bindings | Out Bindings |
---|---|---|---|---|
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 |
As specified in functions.json
, you need Azure Storage account for triggering functions, input & output binding.
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "myitem",
"type": "queueTrigger",
"direction": "in",
"queueName": "itemsqueue",
"connection": "MyStorageConnectionString"
},
{
"name": "inputblob",
"type": "blob",
"path": "inputitems/{queueTrigger}",
"connection": "MyStorageConnectionString",
"direction": "in"
},
{
"name": "outputblob",
"type": "blob",
"direction": "out",
"connection": "MyStorageConnectionString",
"path": "outputitems/{queueTrigger}"
}
]
}
Create an Azure Storage Account
RESOURCE_GROUP="rg-testfunctions"
REGION="japaneast"
STORAGE_ACCOUNT="teststore"
az storage account create --name $STORAGE_ACCOUNT \
--location $REGION \
--resource-group $RESOURCE_GROUP \
--sku Standard_LRS
Create 2 blob containers in the storage you've created: inputitems
and outputitems
# Get Storage Key
ACCESS_KEY=$(az storage account keys list --account-name $STORAGE_ACCOUNT --resource-group $RESOURCE_GROUP --output tsv |head -1 | awk '{print $3}')
az storage container create \
--name "inputitems" \
--account-name $STORAGE_ACCOUNT \
--account-key $ACCESS_KEY
az storage container create \
--name "outputitems" \
--account-name $STORAGE_ACCOUNT \
--account-key $ACCESS_KEY
Create a queue in the storage you've created: itemsqueue
# Get Storage Key
ACCESS_KEY=$(az storage account keys list --account-name $STORAGE_ACCOUNT --resource-group $RESOURCE_GROUP --output tsv |head -1 | awk '{print $3}')
az storage queue create \
--name "itemsqueue" \
--account-name $STORAGE_ACCOUNT \
--account-key $ACCESS_KEY
func host start
Publish the function to the cloud
FUNCTION_APP_NAME="MyFunctionApp"
func azure functionapp publish $FUNCTION_APP_NAME --build-native-deps --no-bundler
Add Functions App Settings
FUNCTION_STORAGE_CONNECTION="*************"
az webapp config appsettings set \
-n $FUNCTION_APP_NAME \
-g $RESOURCE_GROUP \
--settings \
MyStorageConnectionString=$FUNCTION_STORAGE_CONNECTION