Azure functions pre-compiled function, HttpRequestMessage not being passed to function - azure

I have the following F# function signature and beginning of function
let Run(req: HttpRequestMessage, log: TraceWriter) =
async {
log.Info("HttpRequestMessage" + req.ToString())
...
when I execute my function and print the value of req I get
HttpRequestMessageMethod: GET, RequestUri: '<null>', Version: 1.1, Content:
<null>, Headers:{ }
Below is my function.json file
{
"scriptFile": "../WonkTonkLib/wonktonkPostLib.dll",
"entryPoint": "PutUser.Run",
"bindings": [
{
"authLevel": "anonymous",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"methods": [
"post"
]
},
{
"name": "res",
"type": "http",
"direction": "out"
}
],
"disabled": false
}
Any idea why I the request message isn't being passed to the function? Any help is appreciated.

Please make sure your project is referencing System.Net.Http 4.1.1.0 and not a later version.
The current tools and the runtime are both being updated to address this without that requirement, but in the meantime, making sure you're matching that version should address this issue.

Related

Additional Parameter in Node Azure Function

I am just starting to learn to implement Azure Functions with NodeJS and i am trying to add additional custom parameters to the trigger function
as this is the recommended way for input bindings by Microsoft, but I can't get it to work.
I am getting a 404 Not Found Error.
When I remove the id Object from the function.json, the function works, but the id is undefined.
I tried to call the function with get and id as query param and as post with the { id: 123 } in the body, but with no success.
Can anyone help out?
Thanks in advance.
index.ts
const httpTrigger: AzureFunction = async function (
context: Context,
req: HttpRequest,
id: string
): Promise<void> {
context.log("HTTP trigger function processed a request with id.", id);
context.res = {
body: {
id,
},
contentType: "application/json",
};
};
function.json
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "id",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
}
],
"scriptFile": "../dist/respository/index.js"
}
In Node js Azure function we don’t have an Attributes and Annotations so we cannot add additional parameters in azure functions. Attributes are not supported by JavaScript.
In Azure function C# class libraries and Java, the HttpTrigger attribute is available to configure the function.
You can set the authorization level and allowable HTTP methods in attribute constructor parameters, webhook type, and a route template. For more information about these settings, see configuration.
Refer here

What are the differences between the first and second object in the created azure function?

When i run command
func new --name getTodo
i get the following code in my function.json file
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
],
},
{
"type": "http",
"direction": "out",
"name": "res"
}
]
}
so i have two objects in array - what is the difference between the first and the second one ? What are the meanings of "direction": "in", vs "direction": "out", in the second object ?
One means trigger, and another is output binding. Both of them is http.
The trigger give input data by http request, and output binding output data in http response.

How can i query data from my azure cosmos db?

I have azure functions written in nodejs. I can't find a way how to get data for example from my created azure cosmos db. I know that there is azure cosmos SDK, but i don't want to use that way.I want to learn to do it through the azure functions because it is possible with them also.
i try do to this:
function.json
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"type": "cosmosDB",
"name": "inputDocument",
"databaseName": "dbtodos",
"collectionName": "items",
"connectionStringSetting": "todos_DOCUMENTDB",
"partitionKey": "/all",
"direction": "in"
}
],
"disabled": false
}
index
module.exports = async function (context, req) {
context.res = {
// status: 200, /* Defaults to 200 */
body: context.bindings.inputDocument
};
};
after my deploy when i visit the automatically generated url - i can't even open the link.There is not requests coming back.
If i do some basic example where i don't try to pull data from the db then my url is working after deploy.
How can i get the data ?
My data in the local.settings.json was wrong. I had azure storage for other table not for the one that i wanted to query... The code works perfectly fine

Azure function prints out the http error message

I have been trying to execute an azure function. The function does some calculation and returns a json response. If I just print out the json, it gets printed, but the log also contain the below error statement:
2020-06-05T05:03:35.256 [Error] Executed 'Functions.curvefitting' (Failed, Id=8b47fa39-746e-4153-9451-d18bb79ed4cd)
Unable to cast object of type 'System.Byte[]' to type 'Microsoft.AspNetCore.Http.HttpRequest'.
I have coded my main function as:
import azure.functions as af
def main(myblob: af.InputStream) -> str:
json_response = <some calculatios>
return json_response
And here's my function.json file:
{
"scriptFile": "xyz.py",
"entryPoint": "main",
"bindings":[
{
"authLevel": "function",
"type": "blobTrigger",
"direction": "in",
"name": "myblob",
"path": "xyz.xlsx",
"connection": "AzureWebJobsStorage",
"methods":[
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "$return"
}
]
}
Please let me know what I am doing wrong here. I am new to azure functions.
Based on your Json file it looks like you started out with an HttpTriggered function, but you changed it to a BlobTriggered function. Your input binding defines a blobTrigger, but there's also methods there (which are HTTP methods) and the output binding is an HTTP binding.
Most important question is: what are you trying to achieve? If this should be an HttpTriggered function that uses a Blob as input, define an HttpTrigger and an input binding for the blob.
This would be an example of an HttpTriggered Function with an input Blob binding:
{
"scriptFile": "xyz.py",
"entryPoint": "main",
"bindings":[
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req"
},
{
"name": "myblob",
"type": "blob",
"dataType": "binary",
"path": "xyz.xlsx",
"connection": "MyStorageConnectionAppSetting",
"direction": "in"
},
{
"type": "http",
"direction": "out",
"name": "res"
}
]
}
Your main entry point would look something like
def main(req: func.HttpRequest, myblob: func.InputStream) -> func.HttpResponse:
For more information and examples, see Azure Blob storage input binding for Azure Functions and Azure Functions HTTP trigger.

Azure Function binding error for signalR (negotiate function) (500 error code)

I'm creating a live chat using Azure functions and signalR. It works perfectly fine locally, but the deployed "negotiate" function does not work.
negotiate function (index.js)
module.exports = function (context, req, connectionInfo) {
context.res = { body: connectionInfo };
context.done();
}
config file (function.json)
{
"disabled": false,
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req"
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"type": "signalRConnectionInfo",
"name": "connectionInfo",
"hubName": "chat",
"direction": "in",
"connectionStringSetting": "AzureSignalRConnectionString"
}
]
}
AzureSignalRConnectionString is set in function app properties.
I also tried using "connectionString" instead of "connectionStringSetting" and using the connection string instead of "AzureSignalRConnectionString" reference, and all 4 possible combinations we have here.
If I run the function in Azure portal, I get this error:
[Error] Executed 'Functions.negotiate' (Failed, Id=0ac24b1f-1ab0-40f5-9680-34db547e1cc9)
Unable to resolve the value for property 'SignalRConnectionInfoAttribute.ConnectionStringSetting'. Make sure the setting exists and has a valid value
Did you write "connectionStringSetting" as the attribute name in your code ? If so, could you please have a try to change it to "ConnectionStringSetting". You may refer to this tutorial or the screenshot I post below:
Solved (got an answer on https://social.msdn.microsoft.com/).
I should have added the AzureSignalRConnectionString in FunctionApp/Configuration/Application settings instead of FunctionApp/Configuration/Application settings/Connection strings.

Resources