Can an Azure Function trigger itself? - azure

I am trying to do the following with Azure Functions:
url='http://localhost:7071/api/testendpoint'
headers = {
'Content-Type': 'application/json'
}
response=requests.post(url,headers=headers)
i.e. "testendpoint" is another endpoint defined in the same function project. This is what I do: endpoint 1 gets a POST request and then the corresponding function code tries to trigger "testendpoint" with a another POST. If i try to do this locally, the function stops responding and runs into a timeout at some point.
Is it not possible to trigger another endpoint in the same function project? Do I have to split my project into multiple Azure Functions?
Thanks in advance!

It should be possibile.
Please find SO topic regarding this subject
How to call another function with in an Azure function

Related

SAP Cloud SDK for javascript using the destination

I have followed the Tutorial and build the basic CF based nodejs applciation to display all BusinessPartners from my S/4HANA on-premise destination.
function getAllBusinessPartners(): Promise<BusinessPartner[]> {
return BusinessPartner.requestBuilder()
.getAll()
.execute({
destinationName: 'MockServer'
});
}
Destination is configured with the Virtual host from cloud connector.
But after deploying to the Cloud Foundry, i get following error for the GET request
{"message":"Service of type destination is not supported! Consider providing your own transformation function when calling destinationForServiceBinding, like this:\n destinationServiceForBinding(yourServiceName, { serviceBindingToDestination: yourTransformationFunction });","level":"warn","custom_fields":{"package":"core","messageContext":"destination-accessor"},"logger":"sap-cloud-sdk-logger","timestamp":"2020-03-09T18:15:41.856Z","msg":"Service of type destination is not supported! Consider providing your own transformation function when calling destinationForServiceBinding, like this:\n destinationServiceForBinding(yourServiceName, { serviceBindingToDestination: yourTransformationFunction });","written_ts":1583777741856,"written_at":"2020-03-09T18:15:41.856Z"}
The application is already bound to the Destination service as well.
Can someone help me here, what went wrong ? or the approach to use destination is different in the new version of Cloud-SDK ?
After lot of attempts, i have made this to work.
My Observations:
Connectivity service is also required to be bound, when using on-premise S4 backend.
There was no errors in the log, i have made certain modification in the code to use async/await
async function getAllBusinessPartners(): Promise<BusinessPartner[]> {
return await BusinessPartner.requestBuilder()
.getAll()
.execute({
destinationName: 'MockServer'
});
}
After this modification, when I hit the GET request, it gave me the following error:
"Failed to get business partners - get request to http://s4h-scc-basic:500/sap/opu/odata/sap/API_BUSINESS_PARTNER/sap/opu/odata/sap/API_BUSINESS_PARTNER failed!"
Could notice that the suffix after the http://domain:port is twice. One I gave in the destination, and the other VDM adds automatically.
Ideally, this error is supposed to be thrown even before adding async/await.
After removing the suffix from the destination, it started to work.
If your request really does error, what you posted here from your logs is most likely not the reason for the failure. We are aware that this message is confusing and will improve it (https://github.com/SAP/cloud-sdk/pull/32).
Can you check whether there are more errors in your logs? Based on the code you posted and the setup you described, this should work. Do you have a binding to the XSUAA service.

Call azure function from another azure function in javascript

I am new in Azure technology. I have created two functions Master (masterFunction) and Child (childFunction) in Javascript.
I want to invoke Child function from Master function.
I have tried with childFunction.Run(req, log); but its not working.
Please suggest me to fix above issue.
Thanks
This does not work, the azure function actually executes code to meet the trigger conditions. For example, if your childfunction is triggered by a blob, then the way your masterfunction calls it is to satisfy the trigger condition of the childfunction, that is, add operations to the target blob in your masterfunction. If your childfunction is http, then you need to send a request to the childfunction url in the code of the masterfunction.

How to make a function as default in azure function app?

I have an azure function app (abc.azurewebsites.net) and have a function named Function1 defined in it. (abc.azurewebsites.net/api/Function1?code=def==)
Is there a way in which, I can define this Function1 as default and all the incoming requests to abc.azurewebsites.net gets routed to my Function1?
Thanks.
You could use proxy to get this.
Follow this tutorial, and the Route template should be /, and then you should change your function authLevel to anonymous like this.
1.Set the application setting add HELLO_HOST(any parameter same as the backend url) with value <YourBackendApp>.azurewebsites.net.
2.Create the proxy.
3.Set your function to anonymous then your function don't need API keys code to call it.
Then below my test result, it's a HTTP trigger function with query string &name=<yourname>.

Cloud Functions for Firebase error: "400, Change of function trigger type or event provider is not allowed"

When I run firebase deploy I get this error message:
functions: HTTP Error: 400, Change of function trigger type or event provider is not allowed
TL;DR
firebase functions:delete yourFunction // this can be done via the Firebase Console as well
firebase deploy
Explanation
Basically, Cloud Functions expects the same trigger for every function all the time, i.e. once it is created it has to stick to its original trigger because every function name is connected to a specific trigger. The trigger can therefore only be changed by deleting the function first and then creating it again with a different trigger.
This can now be done easily by using the functions:delete command:
firebase functions:delete yourFunction
The documentation features more advanced use cases as well.
Old solution
Solution of this is basically commenting or cutting out your function and then saving the Functions file and deploying. The function will get deleted in Firebase, but after that you can insert/uncomment your function and it will deploy just fine again. This error occurs when you take a function and change the type of trigger that it uses, i.e. HTTP, database or authentication.
Firstly cut it out
/* exports.yourFunction = someTrigger... */
And then, after deploying ("firebase deploy") replace your trigger
exports.yourFunction = anotherTrigger...
For those who stumble upon this in the future, the Cloud Functions console now offers a delete button.
You can also go to the Cloud Functions panel in the Google Cloud Platform console and delete your function from there. After that you can upload the function normally from firebase CLI. Not sure why they don't have a delete function option in the firebase console.

How to use lambda and api getaway to trigger a custom event?

I'm trying to understand how The AWS api gateway works with lambda. What i am wanting to do is quite simple :
When I submit a basic form in a localhosted web page, this simple action should invoke a lambda function.
I know i need to use aws api gateway to complete this action and i read some tutorials online but i can't figure out how to start a lambda function after a custom event.
Thanks yor any help.
It is easier to understand if you work backwards. First, make your custom event handler. Amazon provides a good overview of what you need to do here:
http://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html
If you need more of a kick in the right direction, LithosTech has a well-written guide to handling FORM POST events in Lambda here:
http://lithostech.com/2015/10/aws-lambda-example-contact-form-handler/
At its simplest level, you're going to have a function that takes an event parameter and does something with its values:
var AWS = require('aws-sdk');
exports.handler = function(event, context) {
console.log('Received event:', JSON.stringify(event, null, 2));
// TODO: Do something with event.name, event.email, event.*, ...
}
After you make this function in a .JS file, upload it using the Lambda Web console - you can do it entirely from the command line, but it's easier to use the Web interface when you're first starting out. The biggest benefit to doing it this way is that during the creation process, you'll be asked if you want to make an API gateway endpoint for the function - say yes! This will automatically create a suitable entry for you and give you the details. Drop those in your form and you're off to the races!

Resources