InvalidCastException: Azure Durable Functions Error - javascript

Locally testing Azure Durable Functions with VSCode + JavaScript. Able to successfully trigger the HTTP triggered Orchestration Client and can even see the request headers + body no problem. However, I receive the following error when attempting to trigger the Orchestrator:
Unable to cast object of type 'Microsoft.Azure.WebJobs.DurableOrchestrationContext' to type 'System.String'
I don't understand why DurableOrchestrationContext is trying to be turned into a string.
Code calling the Orchestrator:
context.bindings.patient = [{
FunctionName: "OrchestratorJS",
Input: req,
InstanceId: id
}];
Notes:
- I tried sending just a string as the Input, but to no effect.
- I have successfully created Durable Functions for a different project which makes this even more frustrating.

The Functions runtime is trying to cast DurableOrchestrationContext to a string because of how languages are handled in Functions v2. Unlike v1, v2 runs JavaScript functions through a Node language worker hosted in a different process from the runtime host. The language worker and the host communicate via gRPC protocol. When a function is called, the runtime host must pass bound parameter information to the function over gRPC. Parameters bound to complex objects, like DurableOrchestrationContext, must be serialized to JSON strings, passed via gRPC, and finally rehydrated for a function to consume them.
We introduced DurableOrchestrationContext to string conversion in the 1.4.0 release. Could you try updating to the latest version of the extension (1.5.0) and trying your function again?

Related

cloud function testing failing "Invalid request, unable to process."

I have written a simple cloud function which I also deployed already to firebase and the code works. It is the following function:
exports.testfunction = functions.https.onCall(async (data) => {
const mydata = JSON.parse(data)
const mydata1 = JSON.parse({const1: "AAA", const2: "BBB", const3: "CCC"})
return{mydata1}
});
Now that I want to test this function localy, Im running the following command in my terminal: firebase emulators:start and I get no errors so far. Anyways as soon as I try to call the function with http://localhost:5001/MYPROJECTNAME/us-central1/testfunction in my browser, Im receiving the following error message which I can not find any workaround for:
{"error":{"message":"Bad Request","status":"INVALID_ARGUMENT"}}
The thing is, the function itself is working great if I deploy it and call it from inside my app, but Im failing to run it from my firebase emulator inside the console.
What am I doing wrong here?
As explained in the documentation for Callable Cloud Functions:
It's important to keep in mind that HTTPS callable functions are
similar but not identical to HTTP functions. To use HTTPS callable
functions you must use the client SDK for your platform together with
the functions.https backend API (or implement the protocol).
So, if you want to directly call the function via it's URL, your HTTP Request needs to follow the protocol specification for https.onCall.

AWS SAM: How to locally invoke all Node.js functions instead one by one?

I am developing a REST API with AWS Lambda, API Gateway, RDS (MySQL). I am using Node.js. I am also using AWS SAM tool.
In my API I have lambda functions that accept URL parameters and that do not accept them.
I noticed that I can deploy these to AWS without an issue, and then execute from POSTMAN.
However when I try to locally run them, I am running into problems.
When I execute sam local invoke, it says Error: You must provide a function logical ID when there are more than one functions in your template. So I had to execute them one by one, like sam local invoke FunctionName
When I try to invoke a function that accepts URL parameters, it says TypeError: Cannot destructure property 'id' of 'event.queryStringParameters' as it is undefined. Here the id is the name of the URL Param.
So,
How can I locally invoke all node.js functions, instead of one by one?
How can I make sure that functions with URL Params also can be locally invoked?
In Node.JS, it is not possible to locally invoke all at once. sam local invoke FUNCTION_NAME is the way to go.
Since the question is about a REST API, if you want to check how thE rest api is working, all you have to do is this
sam build
sam local start-api
I normally run the following without build since it helps to view the changes during development:
sam local start-api 2>&1 | tr “\r” “\n”

how to secure api keys in the front-end / client side Javascript?

Scenarios where i require to keep the keys as a secret
Azure / Google Maps API KEYs
STUN & TURN Server credentials for WEBRTC
First I was adding the keys directly , then I found out that those are very high vulnerabilities that others could take those credentials and use it for their needs
Later i tried using environment variables in .env file
But i could not find a way to use it properly
(express + nodeJS)
res.render("pages/crimestats", { apikey: process.env.AZURE_KEY })
here i was passing to the rendering page as a variable , but the key was still visible when i tried to see the source code on the browser.
So what is the proper way to use it ?
What i have in my mind
using an api call to get the key in the frontend
//but then any one can call that api request in the browser console right?

Azure function is not triggered locally

I developed my Azure function app locally using VScode and pushed it to azure cloud, I have eventhub-trigger functions, I used to debug my code locally through VScode normally, but now when I run func host start --debuge, functions in my app started but nothing is triggered, I can see them triggered on the cloud through their log, it drive me mad, why they are not triggered locally, they are enabled, I restarted my function app several times, but I got nothing.
My app is https://butterflyfnapp.azurewebsites.net
In additional to Mikhail, other option is to create a separate consumer group of the Event Hub for each environment such as a cloud and development/VS and configured them in the Application settings or local.settings.json.
Then add the ConsumerGroup = "%consumergroup%" to the EventHubTrigger argument in your function, where the consumergroup is an example of the variable name in the settings.
Beside the above options, still you have a capability for testing a non-Http trigger function locally using a Http POST request. In other words, your function can be tested locally the same way like is done in the portal. More details here.
The following is an example of the testing EventHubTrigger function using a Http POST request:
url: http://localhost:7071/admin/functions/MyFunction
payload:
{
"input": '{"Id":1234,"Name":"abcd"}'
}
Event Hub consumer information (checkpoints) are stored in Blob Storage. If you share the connection string to Blob Storage between development / production environments, they will use the same checkpoints, so they will compete against each other.
My guess is that your cloud deployment always processes the events, updates the checkpoint to the latest position, and then local deployment takes this checkpoint and doesn't do anything.
To make sure this doesn't happen, create an additional "dev" Blob Storage and set the local connection string setting to that storage.

Is there an equivalent of Netscape navigator functions in nodejs?

Can I access the inbuilt navigator functions like isinNet() or DomainNameorHost() from nodejs?
Since nodeJS runs on the server, not the browser, you can't access functions that are only provided in a browser.
Most developers use a middleware like Express to create a web service on nodejs.
In a route, such as
app.route("/play", function(req,res){
// code that handles URL /play
});
there is a callback function that is called when a request arrives for that route.
The req object parameter contains everything about the request.
req.ip is the upstream (incoming) ip address.
I looked around in npm for a module that might map remote ips to hostnames and could not find one. Presumably all it would do is reverseDNS, which could take time and hold up processing requests.

Categories

Resources