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

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>.

Related

What do i put in the "handler" prop of aws-cdk's gateway.LambdaRestApi?

I'm building out one of my first gateway api's and have been reading the code and documentation here.
For an apigateway which use made using the LambdaRestApi function, my understanding was that i define the endpoints and the lambda attached to the endpoints.
If that's the case, what do i put as the functions handler function? I don't have any plans for there to be a base route for it so do i have to just have a blank lambda here? Or am i going in the wrong direction with my thinking?
LambdaRestApi is just a utility construct based on RestApi with defaultIntegration to a Lambda function.
You can use a plain RestApi instead if you don't need the default proxy integration to a Lambda handler configured.

Getting ExecutionContext in other libraries/projects in Azure Function App

The execution context that is injected to a function (https://github.com/Azure/azure-functions-host/wiki/Retrieving-information-about-the-currently-running-function), is it possible to get it in some other helper libraries.
I want to get the InvocationId of the current function in some other libraries. For e.g. let's say I have written a logger and I need to add the Invocation ID for every log. One trivial way to achieve this would be to pass the Invocation ID from the function to all the helpers, but it may not be possible especially if one is working with legacy code.
In App services we could solve this problem by getting access to the HttpContext via the IHttpContextAccessor.
Is there any alternative to this in Azure function?

How to do unit testing for a function calling a private function , which makes an external API call in nodejs?

How to do unit testing for a function calling a private function , which makes an external API call in nodejs. What i want is that my test should not be dependent on response from an external call and I thought of mocking the private function through which API call is made but I can't seem to achieve that. What should be a good approach to resolve this?
You can mock/stub the package you are using to call the external API (http, request, etc). By doing that, you don't need to depend on any external resource, and also, you don't need to change you code to expose and override/mock the private function code.

Precompiled Azure Function and SOAP endpoints

I'm writing a precompiled Azure function that will perform a SOAP call to ServiceNow. The code works as a standalone exe but I can't seem to get it converted to a precompiled function. In know it's because my DLL can't find the app.config file but what's the best way to get around it. Error message below. ServiceNow requires I set certain bindings and endpoint configuration. The other contractors for their ServiceNowSoapClient class allow me to specify a url directly but don't seem to allow me to get to the binding settings.
Exception while executing function: Functions.TimerTriggerCSharp.
System.ServiceModel: Could not find endpoint element with name
'ServiceNowSoapDev' and contract 'ServiceNowReference.ServiceNowSoap'
in the ServiceModel client configuration section. This might be
because no configuration file was found for your application, or
because no endpoint element matching this name could be found in the
client element.
In WCF you can define your client binding and endpoint programmatically instead of using app.config. Use the constructor of the generated client with two parameters:
new ServiceNowSoapClient(binding, remoteAddress);
See more code here.

Cloud Endpoint URL in cron.xml App Engine

I'm trying to set up a cron job in App Engine that executes a GET request over a Cloud Endpoint method.
I've created the GET method in an Endpoint class with the #API annotation
#ApiMethod(name = "cron.test", path="cron/test", httpMethod = HttpMethod.GET)
public void testCron() {
... // do something
}
In cron.xml I've set:
<cronentries>
<cron>
<url>/_ah/api/MYAPI/v1/cron/test</url>
<description>Send nightly reports.</description>
<schedule>every 1 minutes</schedule>
<timezone>America/Los_Angeles</timezone>
</cron>
</cronentries>
Cron Jobs view in App Engine admin panel shows that the cron tries to execute but fails. What am I doing wrong? Is the URL to the endpoint method wrong?
The URLs under /_ah/api are not owned by your application, they are owned by Google's API infrastructure, and so your application won't receive those requests.
A few things to consider:
Abstract the behavior into a helper method and call that in your cron handler
Use the /_ah/spi handler you've defined directly
PS In the future, it'd be helpful to also include any errors from your logs or not that you didn't see any (which is almost certainly going to be true here, for reasons mentioned above).

Resources