I am new in AZURE. I have created multiple functions in AZURE with API URL. Some function contains API URL with CODE parameter and some are without CODE parameter.
Can any one let me know how to remove the CODE parameter from the API URL?
e.g
1) With paramter: API_URL?code=oxwOFsfARhzBZpworHGR9cKeN/Mns0L6s4daqQuJft8ui84yYdbOfQ==
2) Without parameter: API_URL
Thanks
Just set the authLevel to anonymous:
{
"generatedBy": "Microsoft.NET.Sdk.Functions-3.0.9",
"configurationSource": "attributes",
"bindings": [
{
"type": "httpTrigger",
"methods": [
"get"
],
"authLevel": "anonymous",
"name": "req"
}
],
"disabled": false,
"scriptFile": "YOUR-DLL",
"entryPoint": "YOUR-ENTRY-POINT"
}
Check out Azure Function Proxies - https://learn.microsoft.com/en-us/azure/azure-functions/functions-proxies
That should help with presenting a "friendly URL".
Related
I'm trying to use a filter on an Azure function to look up a row in a table based on an optional route parameter. If the parameter isn't provided, or doesn't match a row, a default row should be returned. This works if I provide a matching value, or a wrong value, I get a row as I expect. If I provide no value at all, I get the following error:
Exception while executing function: Functions.link. Microsoft.Azure.WebJobs.Extensions.Storage: Object reference not set to an instance of an object.
The three key bits (AFAIU) are:
httpTrigger route: "link/{ref?}"
Table filter: "Email eq '{ref}' or Default eq true"
Endpoint URL: https://[subdomain].azurewebsites.net/api/link/(ref)
Is there some way to construct the filter or route so that I get the second clause of the filter when the optional parameter is not provided? Or is there a better way to do this?
My full function.json looks like this:
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"route": "link/{ref?}",
"direction": "in",
"name": "req",
"methods": [
"get"
]
},
{
"name": "emailRule",
"type": "table",
"take": "1",
"filter": "Email eq '{ref}' or Default eq true",
"tableName": "RedirectRules",
"connection": "TestStorageConnectionAppSetting",
"direction": "in"
},
{
"type": "http",
"direction": "out",
"name": "res"
}
]
}
Try to use this route "route": "link/{ref=''}", this way you dont have null value but always empty string
I started tinkering with Azure SignalR and ran into a problem with the negiotate trigger.
I followed this official Microsoft guide:
Heres my Code:
local.settings.json
{
"IsEncrypted": false,
"Values": {
"AzureSignalRConnectionString": "Endpoint=https://my.service.signalr.net;AccessKey=myKey=;Version=1.0;",
"FUNCTIONS_WORKER_RUNTIME": "node"
},
"Host": {
"LocalHttpPort": 7071,
"CORS": "*",
"CORSCredentials": true
}
}
function.json
{
"disabled": false,
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"methods": [
"get"
],
"name": "req",
"route": "negotiate"
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"type": "SignalRConnectionInfo",
"name": "connectionInfo",
"hubName": "jitsi",
"ConnectionStringSetting": "Endpoint=https://my.service.signalr.net;AccessKey=myKey;Version=1.0;",
"direction": "in"
}
]
}
index.js
module.exports = async function (context, req, connectionInfo) {
context.res.body = connectionInfo;
};
It works fine locally (unfortunately thats where the guide ends). But if I visit the URL of the negotiate http-trigger I get "Internal Server Error 500". Logs contain following output.
2020-04-23T08:47:32 Welcome, you are now connected to log-streaming service. The default timeout is 2 hours. Change the timeout with the App Setting SCM_LOGSTREAM_TIMEOUT (in seconds).
2020-04-23T08:47:52.070 [Information] Executing 'Functions.jitsiNegotiate' (Reason='This function was programmatically called via the host APIs.', Id=2b791d95-3775-47bb-ade1-ac9005929f61)
2020-04-23T08:47:52.238 [Error] Executed 'Functions.jitsiNegotiate' (Failed, Id=2b791d95-3775-47bb-ade1-ac9005929f61)
Unable to resolve the value for property 'SignalRConnectionInfoAttribute.ConnectionStringSetting'. Make sure the setting exists and has a valid value.
As you can see in my code I did provide the ConnectionStringSetting.
Some People suggested it's due to lower/upper case 'C' in ConnectionStringSetting.
Others said to to edit local.settings.json.
None of that had any effect for me and I can't find any useful information on the issue.
EDIT 1:
I set "hubName":"jitsi". With jitsi being the name of my SignalR Service.
As in 'jitsi.service.signalr.net'. I'm not sure if that's correct or not.
Perhaps thats part of the issue?
EDIT 2:
I tried with no value set for ConnectionStringSetting (so that it goes to default).
Gave me same error. I also completely deleted any content of local.settings.json and then re-deployed to see what would happen.
Same behaviour as before.
My guess is The service only uses the file for local usage (hence the name).
So with the local.settings.json being empty theres no place else where I defined the value for AzureSignalRConnectionString.
I did some digging and apparently (according to this thread) you should define it under
'Configuration'->'Application Settings'
So I created a new setting with
name: Azure__SignalR__ConnectionString
value: myMaskedConnectionString
Which resulted in the following error:
The SignalR Service connection string must be set either via an 'AzureSignalRConnectionString' app setting, via an 'AzureSignalRConnectionString' environment variable, or directly in code via SignalROptions.ConnectionString or SignalRConnectionInfoAttribute.ConnectionStringSetting.
I found a resolution to this issue:
I got confused at first and thought the local.settings.json would serve as configuration for the live/non-local version of the function. That's not the case. It's only for local execution (could've guessed by the name of the file)
So the question remains: Where/How can I edit the required settings in the Azure Portal?
Answer:Home -> All Services -> Function-App -> MyFunctionApp -> Platform Features -> Configuration -> Application Settings -> Create New Application Setting
name: AzureSignalRConnectionString
value MyMaskedConnectionString
Then in function.json like this:
{
"disabled": false,
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"methods": [
"get"
],
"name": "req",
"route": "negotiate"
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"type": "SignalRConnectionInfo",
"name": "connectionInfo",
"hubName": "jitsi",
"direction": "in",
"connectionStringSetting": "AzureSignalRConnectionString"
}
]
}
With those settings it's working for me now.
I'm trying access HTTP trigger python function that's running inside Azure container.
I've followed the below url
https://learn.microsoft.com/en-us/azure/azure-functions/functions-create-function-linux-custom-image
When I'm testing my azure function in python, I'm getting HTTP ERROR 401.
How to resolve it and the following is my docker run command
docker run -p 8000:80 -it <dockerid>/mydockerimage:v1.0.0
There's not enough information here to help you; however, you need to make sure that if you've set AuthorizationLevel.Function, such as in here:
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
...you need to ensure that you are including x-functions-key header in your request, or you can get the URL of the function:
The URL will have the code appended to it.
If you want to allow anonymous access to a Python Azure Function, you can set it in the function.json file in the folder of that function.
E.g. see the "authLevel": "anonymous" value in this sample:
(the default value is "authLevel": "function")
{
"scriptFile": "__init__.py",
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "$return"
}
]
}
When I deploy an Azure Function from Visual Studio, the function.json file is always incorrect. An example of the function.json file is the following for a queue triggered function:
{
"generatedBy": "Microsoft.NET.Sdk.Functions-1.0.12",
"configurationSource": "attributes",
"bindings": [
{
"type": "queueTrigger",
"connection": "AzureWebJobsStorage",
"queueName": "queue",
"name": "myQueueItem"
}
],
"disabled": false,
"scriptFile": "../bin/x.dll",
"entryPoint": "x"
}
The correct function.json in order for the function to work in azure is:
{
"bindings": [
{
"type": "queueTrigger",
"connection": "AzureWebJobsStorage",
"direction" : "in",
"queueName": "queue",
"name": "myQueueItem"
}
],
"disabled": false,
"scriptFile": "../bin/x.dll",
"entryPoint": "x"
}
Is there any solution to automated deployments/ Visual Studio deployments that would do this automatically? Currently I am editing all the function.json files every deployment. Any solutions or workarounds would be appreciated.
Agree with #Thomas, have tested v1 queue trigger template with Microsoft.NET.Sdk.Functions-1.0.12 and latest Microsoft.NET.Sdk.Functions-1.0.22, function.json generated by VS does work.
Actually two function.json both work on Azure, those two line below are used to tell function.json is generated by VS and not recommended to be modified after deployment.
"generatedBy": "Microsoft.NET.Sdk.Functions-1.0.22",
"configurationSource": "attributes",
The first one would not work
Function execution result may not be shown instantly, you could go to https://functionappname.scm.azurewebsites.net/DebugConsole and navigate to D:\home\LogFiles\Application\Functions\function\{FunctionName} to check log files.
Also you can visit D:\home\LogFiles\Application\Functions\Host to detect detailed host logs.
If you are still troubled, you could elaborate would not work with details and show us your code.
I know that I can get the host key and trigger_url of an Azure Function in an ARM template by using the listKeys/listSecrets method.
But I need the systemkey, I'm deploying an Event Grid Subscription and it needs the Azure Function endpoint url which contains the system key:
"resources": [
{
"type": "Microsoft.Storage/StorageAccounts/providers/eventSubscriptions",
"name": "[concat(concat(parameters('publisherName'), '/Microsoft.EventGrid/'), parameters('name'))]",
"apiVersion": "2018-01-01",
"properties": {
"destination": {
"endpointType": "[parameters('endpointType')]",
"properties": {
"endpointUrl": "[parameters('endpointUrl')]"
}
},
"filter": {
"subjectBeginsWith": "[parameters('subjectBeginsWith')]",
"subjectEndsWith": "[parameters('subjectEndsWith')]",
"subjectIsCaseSensitive": "[parameters('subjectIsCaseSensitive')]",
"includedEventTypes": "[parameters('includedEventTypes')]"
},
"labels": "[parameters('labels')]"
}
}
]
where endpointUrl is in the form of:
https://<function-app-name>.azurewebsites.net/admin/extensions/EventGridExtensionConfig?functionName=<function-name>&code=XZvGU0ROPxxxxxxxxxxxxxxxxxxxxxxxxxxxxaaieD89gPQ==
The parameter named 'code' is the systemkey, which can be retrieved by doing a GET on
http://<function-app-name>.azurewebsites.net/admin/host/systemkeys/eventgridextensionconfig_extension?code=<master_key>
Is there a way to retrieve this systemkey (or the entire endpointurl) in the ARM template without resorting to bash scripts that inject it or other external systems?
The documentation does say: "However, you cannot use list operations that require values in the request body." So I don't think I'll be able to with a 'list' operation.
Yes, it is now possible:
"destination": {
"endpointType": "WebHook",
"properties": {
"endpointUrl": "[concat(variables('functionUrl'), listKeys(resourceId(variables('functionResourceGroupName'), 'Microsoft.Web/sites/host/', variables('functionAppName'), 'default'),'2016-08-01').systemkeys.eventgrid_extension)]"
}
},
Where functionUrl ends with &code=. Tested that on runtime ~2.
This is not possible right now. You can return only function keys using the ARM template.
Same described here:
https://blog.mexia.com.au/list-of-access-keys-from-output-values-after-arm-template-deployment#functions