In Azure Portal, you can get function URL directly from portal. there is also another way here that you can get Azure Function URL using Azure ARM API. But I want to know, Is there any way to get "Function URL" by code (Node.js, Python, ...) in Azure Function Apps directly?
For Node.js azure function, you can just use this line of code: req.originalUrl.
Detailed steps as below:
1.In Azure portal, create a Http Trigger function, select JavaScript as it's Programming Language.
2.In the index.js file, add this line of code: context.log(req.originalUrl);
3.Sample code like below:
module.exports = function (context, req) {
context.log(req.originalUrl);
//write you other logic below
};
Please refer to the screenshot below for test result:
Related
I am accessing my configuration stored in Azure Appconfiguration. I am using SDK (Azure.Data.AppConfiguration) from Azure function. Following the example from https://github.com/Azure/azure-sdk-for-net/blob/Azure.Data.AppConfiguration_1.0.2/sdk/appconfiguration/Azure.Data.AppConfiguration/samples/Sample2_HelloWorldExtended.md
I am keep getting 400 error.
Following is my code
var client = new ConfigurationClient(_azureAppConfigurationOptions.ConnectionString);
ConfigurationSetting setting = client.
GetConfigurationSetting(
"appid");
the only difference is i am calling from Azure functions.
Any help or insight is appreciated.
When try to get configuration(app settings) in azure function, you should use this method Environment.GetEnvironmentVariable(xxx).
Please refer to this article for details.
My Requirement:
As soon as a file being uploaded to a Blob Container, the Azure Function is being alerted and withing that Azure Function I want to call a Webjob who uses the uploaded file and does any task.
What I learnt:
I learnt that Azure Function can be triggered when a file being uploaded to a blob container. I tried the tutorials and was able to configure an Azure function and it acts for any change in blob container. I did this via Azure Portal and not used Visual Studio.
Now I want to call a WebJob within the Azure Function. Please help me on this.
Assuming that you have written your function in C#, below is the code that might help you. Essentially the idea is to send a POST request to trigger your job:
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(“https://your_web_site.azurewebsites.net/api/”);
var byteArray = Encoding.ASCII.GetBytes(“your_username:your_password”);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(“Basic”, Convert.ToBase64String(byteArray));
var response = await client.PostAsync(“triggeredwebjobs/your_web_job_name/run”, null);
Username and password you find in Azure portal, in the properties of your job.
I have a function app hosted on azure when I get the url endpoint of the function it says https://my_function_app.azurewebsites.net/api/{*segments} instead of https://my_function_app.azurewebsites.net/api/function_name. How do I fix this?
Looks like you have set route template.
If you create function on portal, click Integrate blade and delete values in Route template.
If you deploy pre-complied function to Azure, you should remove this setting in your code.
For c#, set Route=null in HttpTrigger attribute in your .cs file. For js, remove route parameter in function.json file.
I want to call a Azure function after PostDeployment. So I have a created a HttpTriggerCsharp Azure function.
I have done the following:-
Go to Kudu console
Tools
Web hooks
Add HttpTriggerCsharp Azure
function URL with PostDeployment option.
I am using Git-hub for
deployment. I am doing push now.
HttpTriggerCsharp Azure function is
called and executed. But I see Status and Reason of the Web hook as
Bad Request. Refer
Why I am Status and Reason as "Bad Request"? What is the issue here?
I have removed the code which relates to request body ( dynamic data = await req.Content.ReadAsAsync();).
Now my code is working now.
I've been looking around and I can't find a concise example around getting this metric. I've installed WindowsAzure.Management.Compute and now I don't know where to begin. How can this be done?
I would recommend you to take a look at Azure Resource Explorer: https://resources.azure.com. You could find the instances request URL as following:
For the Authorization header please have a look at this article. We can use C# HttpRequest to write the code. Here is the result I tested in fildder.
the endpoint:
https://management.azure.com/subscriptions/<subscription id>/resourceGroups/jatestgroup/providers/Microsoft.Web/sites/testcore1/instances?api-version=2015-08-01
Result:
We can calculate the instance number from the response json. In addition, it will need a long time in this rest API to show all instances when scale the instance in azure portal.
[Update]
According with my comment, I tested with the article:http://blog.amitapple.com/post/2014/03/access-specific-instance/#.V9tLKyh95hF
The following is my result:
Please download the library at here. Refer to this article for more information about Windows Azure Management Certificates.
Here is the code snipped:
var cert = new X509Certificate2();
cert.Import(Convert.FromBase64String(""));
var _client = new Microsoft.WindowsAzure.Management.WebSites.WebSiteManagementClient(new Microsoft.WindowsAzure.CertificateCloudCredentials("****", cert));
var ids= await _client.WebSites.GetInstanceIdsAsync("EastAsiawebspace", "testcore1");
You cannot get the instance count from within one instance of the Web App. But you can get it from the portal, or from the Azure ARM API (it's the numberOfWorkers property on the Web Hosting Plan object).
Also, note that WindowsAzure.Management.Compute does not apply to Azure Web App.