- mti-example provides a function to load JSON files into a storage container satrigger000sc FaaS-on-Azure.md gives an example
- mti-satrigger provides a function which is triggered every time the storage container is updated
az account set --subscription "Free Trial"
az storage account list -o table
az group create --name satrigger000rg --location westeurope
az storage account create --name satrigger000sa --resource-group satrigger000rg --location westeurope --kind StorageV2 --sku Standard_LRS
az storage container create --auth-mode login --account-name satrigger000sa --name satrigger000sc
az functionapp plan create --name satrigger000sp --resource-group satrigger000rg --location westeurope --sku B1
az functionapp create --runtime node --runtime-version 10 --functions-version 2 --resource-group satrigger000rg --storage-account satrigger000sa --name mti-satrigger --plan satrigger000sp
az functionapp create --runtime node --runtime-version 10 --functions-version 2 --resource-group satrigger000rg --storage-account satrigger000sa --name mti-example --plan satrigger000sp
func init satrigger --javascript
cd satrigger
func new --name mti-satrigger --template "Azure Blob Storage trigger"
The path must contain the name of the storage container which is to be monitored for change.
{
"bindings": [
{
"name": "myBlob",
"type": "blobTrigger",
"direction": "in",
"path": "satrigger000sc",
"connection": ""
}
]
}
This is a very simple function it writes to the log file 'D:\home\LogFiles\Application\Functions\Function\' which can be seen in the Diagnostic Console
module.exports = async function (context, myBlob) {
context.log("JavaScript blob trigger function processed blob \n Blob:", context.bindingData.blobTrigger, "\n Blob Size:", myBlob.length, "Bytes");
};
func azure functionapp publish mti-satrigger --force --javascript
From the Azure Portal it is possible to open the url
https://<function-name>.scm.azurewebsites.net/DebugConsole/?shell=powershell`
e.g.
https://mti-satrigger.scm.azurewebsites.net/DebugConsole/?shell=powershell
at this point it is possible to select Powershell and then enter
cd D:\home\LogFiles\Application\Functions\Function\mti-satrigger
PS D:\home\LogFiles\Application\Functions\Function\mti-satrigger> dir
Directory: D:\home\LogFiles\Application\Functions\Function\mti-satrigger
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 8/28/2020 3:17 PM 1538 2020-08-28T15-15-26Z-1a57a3cf72.log
This log file can then be monitored for output from the function
Having a trigger executing when an update occurs to the storage container is more useful when it can cause other things to happen. In this case we want to to call another REST API function
This is a simple change. Update the index.js to continue the new code
const https = require("https")
module.exports = async function (context, myBlob) {
context.log("JavaScript blob trigger function processed blob \n Blob:", context.bindingData.blobTrigger, "\n Blob Size:", myBlob.length, "Bytes");
//---
let body = JSON.stringify({
name: "mtidev000ixr",
dataSourceName: "mtidev000ds",
targetIndexName: "mti-results2"
})
let options = {
hostname: "mtidev000ss.search.windows.net",
path: "/indexers/mtidev000ixr/run?api-version=2020-06-30",
port: "443",
method: "POST",
headers: {
"Content-Type": "application/json",
"api-key": "262EXXXXXXXXXXXXXXXXXXXXXXXCD4",
"Content-Length": Buffer.byteLength(body)
}
}
https
.request(options, res => {
let data = ""
res.on("data", d => {
data += d
})
res.on("end", () => {
console.log(data)
})
})
.on("error", console.error)
.end(body)
//--
};
func azure functionapp publish mti-satrigger --force --javascript