I have an Azure Function App with a function at the URL http://localhost:7072/api/create-room along with other functions. This particular function is a HTTPTrigger with allowed anonymous access and accepts the GET verb:
[HttpTrigger(AuthorizationLevel.Anonymous, "get")]
Along with that, I have a separate function app that hosts only a proxies.json file and serves only as a functions proxy. My proxies function is running on port 7071 locally.
My proxies file currently looks like this:
{
"$schema": "http://json.schemastore.org/proxies",
"proxies": {
"chatNegotiate": {
"matchCondition": {
"route": "/api/chat/negotiate",
"methods": [
"POST"
]
},
"backendUri": "%chat_api%/api/BeginNegotiate"
},
"chatMessages": {
"matchCondition": {
"route": "/api/chat/messages",
"methods": [
"POST"
]
},
"backendUri": "%chat_api%/api/PostMessage"
},
"createRoom": {
"matchCondition": {
"route": "/api/create-room",
"methods": [
"GET"
]
},
"backendUri": "%session_api%/api/CreateRoom"
}
}
}
When both of these function apps are deployed to Azure, everything works like a dream. I can make requests, they're forwarded on, requests come back. It's all glorious.
However, when I run these functions locally, the request is never forwarded on from the proxy, with the proxy returning a 404. I can hit the function on the other function app running locally on 7072 directly and all is well there, but not at all when I got via the proxy.
The proxy itself returns:
[30/05/2020 18:24:30] Host lock lease acquired by instance ID '0000000000000000000000002D5B6BEA'.
[30/05/2020 18:24:34] Executing HTTP request: {
[30/05/2020 18:24:34] "requestId": "9004b8e2-f208-4a98-8b48-6f85bca41281",
[30/05/2020 18:24:34] "method": "GET",
[30/05/2020 18:24:34] "uri": "/api/create-room"
[30/05/2020 18:24:34] }
[30/05/2020 18:24:34] Executed HTTP request: {
[30/05/2020 18:24:34] "requestId": "9004b8e2-f208-4a98-8b48-6f85bca41281",
[30/05/2020 18:24:34] "method": "GET",
[30/05/2020 18:24:34] "uri": "/api/create-room",
[30/05/2020 18:24:34] "identities": [],
[30/05/2020 18:24:34] "status": 404,
[30/05/2020 18:24:34] "duration": 15
[30/05/2020 18:24:34] }
From examples I've looked at such as https://chsakell.com/2019/02/03/azure-functions-proxies-in-action/, this should be working fine.
Any suggestions? Thanks in advance for any help you can provide!
I've solved this after all.
proxies.json isn't set to copy to the output directory by default.
You need to ensure that it's set to copy always.
In Visual Studio:
Right click proxies.json > click properties > Set Copy to output directory to Copy Always.
In Visual Studio Code (and other editors):
Open ProjectName.csproj and add an entry to always copy proxies.json to output directory.
<ItemGroup>
<None Update="proxies.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
This solved the problem with the 404 on my local instance of the function app proxy. In local.settings.json add this to Values:
"AZURE_FUNCTION_PROXY_DISABLE_LOCAL_CALL": true,
Credit: https://chsakell.com/2019/02/03/azure-functions-proxies-in-action/
Related
As of now, from what I see, the only way to use Azure Function Proxy is to re-route an existing api is to call upon that api directly. For example:
Backend URL
https://gateway-api.com/api/getSomething
Route Template
/api
Proxy URL
https://gateway.azurewebsites.net/api
What I want is to have the Backend URL pass through any endpoint relative to the main endpoint.
Effectively this:
Backend URL
https://gateway-api.com/* or i even tried this https://gateway-api.com/{*restOfPath}
This way, any api's that follow the core domain URL will still work as expected.
Here is a re-write of the example above:
Backend URL 2
https://gateway-api.com/*
Route Template 2
/*
Proxy URL 2
https://gateway.azurewebsites.net/api/getSomething
When I do this I can't get it to work or even reach the debuger to log anything.
Is this possible and if not would this be something Azure API Management would be able to accomplish?
Can you provide your configuration file? this is mine:
Proxies.json:
{
"$schema": "http://json.schemastore.org/proxies",
"proxies": {
"proxy1": {
"matchCondition": {
"methods": [ "GET" ],
"route": "/{test}"
},
"backendUri": "http://localhost:7071/abc/Function1"
}
}
}
host.json:
{
"version": "2.0",
"extensions": {
"http": {
"routePrefix": "abc"
}
},
"logging": {
"applicationInsights": {
"samplingExcludedTypes": "Request",
"samplingSettings": {
"isEnabled": true
}
}
}
}
This is the backend url and proxy of my function:
Both of them works fine.
If you change route template, I think the backend url will not have /api unless you give the /api to routePrefix.
Any way, please show the file about how to configure proxy and route template.
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".
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"
}
]
}
I am creating an Azure Logic App that will create a new file (from HTTP body content of about 5KB) on an FTP server.
Here is the FTP Create File code snippet:
{
"inputs": {
"host": {
"connection": {
"name": "#parameters('$connections')['ftp']['connectionId']"
}
},
"method": "post",
"body": "#body('Provider_Post')",
"path": "/datasets/default/files",
"queries": {
"folderPath": "/",
"name": "filename_#{utcNow()}.xml",
"queryParametersSingleEncoded": true
},
"authentication": "#parameters('$authentication')"
},
"runtimeConfiguration": {
"contentTransfer": {
"transferMode": "Chunked"
}
}
}
This step takes really long (32 minutes) and then fails with following error:
MaxRequestCountReached. The maximum number of requests allowed '1000' was not sufficient to upload the entire content. Uploaded content length: '2378'. Total content length: '4877'.
The file appears on the FTP server but only 2380 bytes from the end of the file is there.
What does this error mean and how to fix it? 5KB shouldn't be too much of data. Is this something about the FTP server? I can send the file with FileZilla without problems.
I even tested this so that I created another step (before the failing one) that will send the HTTP content statusCode (so, just "200") to a new file and it writes it, succesfully, in one second.
The reason this misbehaved was that I had disabled Binary Transport in the ftp API connection settings.
When I enabled the Binary Transport checkbox, it wrote the file in seconds.