Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Function Docker not working with http trigger

Recently I have created a docker image with Azure Function (Node) having HttpTrigger. This is a basic HttpTrigger which generate by default. I'm developing this on Macbook Pro (MoJave) and I have following tools installed.

NodeJs - node/10.13.0 .NET Core 2.1 for macOS Azure Function core tools (via brew)

When I run the function locally with "func host start", it all works fine and I could see the function loading messages. Also I was able to execute the Azure function with trigger endpoint.However, when I try to build the Docker container and run the same, I can load the home page of the app but could not reach the function endpoint. In the log I could only see following;

Hosting environment: Production
Content root path: /
Now listening on: http://[::]:80
Application started. Press Ctrl+C to shut down.

My Docker file is as below (generated by Azure core tools);

FROM mcr.microsoft.com/azure-functions/node:2.0
ENV AzureWebJobsScriptRoot=/home/site/wwwroot
COPY . /home/site/wwwroot

When I try to to use 'microsoft/azure-functions-runtime:v2.0.0-beta1' as base image, then I can see the function loading and could able to access the http trigger also.

Is there anything missing or do I need to use a different image?

like image 364
Melanga Avatar asked Nov 21 '18 12:11

Melanga


People also ask

Can you trigger an Azure function using an HTTP request?

Azure Functions may be invoked via HTTP requests to build serverless APIs and respond to webhooks.

Why is my Azure not triggering?

The most common cause for Azure Functions not getting triggered is that triggers are not synced properly. You can sync triggers in one of three ways: Restart your function app in the Azure portal.

How run HTTP trigger Azure function in Visual Studio?

To start your function in Visual Studio in debug mode: Press F5. If prompted, accept the request from Visual Studio to download and install Azure Functions Core (CLI) tools. You might also need to enable a firewall exception so that the tools can handle HTTP requests.

How do I manually trigger Azure function?

Navigate to your function app in the Azure portal, select App Keys, and then the _master key. In the Edit key section, copy the key value to your clipboard, and then select OK. After copying the _master key, select Code + Test, and then select Logs.


1 Answers

  1. In Dockerfile, add ENV AzureFunctionsJobHost__Logging__Console__IsEnabled=true to enable logging, the setting is omitted in the basic image so we have to do it manually for now.

  2. If you got 401 Unauthorized, find the file function.json, change authLevel to anonymous if it was function(default value in template). We can't access http trigger in a local container with authlevel other than anonymous. Because we don't have function keys yet, which are available after we create a Function app using the container.

    As for why we can access http trigger with function authlevel when we use func host start out of container, authorization is disabled regardless of the specified authentication level when running locally.

like image 94
Jerry Liu Avatar answered Nov 11 '22 14:11

Jerry Liu