I have been attempting to create an Azure Function with PowerShell based on what I mentioned in the title and have been getting the following error. I will also attach the code blocks from the function.json and run.ps1 files:
ERROR
2023-07-05T10:17:33.175 [Error] Executed 'Functions.HttpTrigger1' (Failed, Id=ef2aae22-df71-4027-b936-21fa2ef56f54, Duration=2ms)Result: FailureException: No input binding defined for the parameter 'res' that is declared in the script or function.Stack: at Microsoft.Azure.Functions.PowerShellWorker.AzFunctionInfo..ctor(RpcFunctionMetadata metadata) in /mnt/vss/_work/1/s/src/FunctionInfo.cs:line 134at Microsoft.Azure.Functions.PowerShellWorker.FunctionLoader.LoadFunction(FunctionLoadRequest request) in /mnt/vss/_work/1/s/src/FunctionLoader.cs:line 52at Microsoft.Azure.Functions.PowerShellWorker.RequestProcessor.ProcessFunctionLoadRequest(StreamingMessage request) in /mnt/vss/_work/1/s/src/RequestProcessor.cs:line 224
RUN.PS1
`using namespace System.Net
param($req, $res)
# Retrieve the values of the parameters from the parameter section
$name1 = $req.Query.name1
$name2 = $req.Query.name2
# Construct the response body with the parameter values
$responseBody = "$name1 $name2"
# Create the HTTP response
$res = [HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $responseBody
}
# Output the response to the output binding
$res`
FUNCTION.JSON
`{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
}
],
"disabled": false
}`
ADDTIONAL INFO Input Parameters
Any help with this issue would be greatly appreciated.
I have reproduced in my environment and got expected results as below:
function.json:run.ps:Input:Output:In this process(code), I have used Response(In Associate values to output ,part of code) as (Push-OutputBinding -Name Response) the variable which stores concatenated variable value.