ShaneKm
ShaneKm

Reputation: 21308

Azure Functions Not able to hit HttpTrigger

I have a simple Azure function with HttpTrigger like so:

[FunctionName("Heartbeat")]
public async Task<IActionResult> Heartbeat(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "heartbeat")] HttpRequest req,
    ILogger log)
{
    log.Log(LogLevel.Information, "Received heartbeat request");
    var status = await _healthCheck.CheckHealthAsync();

    return new OkObjectResult(Enum.GetName(typeof(HealthStatus), status.Status));
}

local.settings.json:

{
  "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=false",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet",
        "APPINSIGHTS_INSTRUMENTATIONKEY": "*****"
    },

    "ConnectionStrings": {
        "ServiceDb": "Server=.;Initial Catalog=Acquire;Integrated Security=True;"
    },

  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },

When i run the function locally I'm able to hit a breakpoint inside Heartbeat() and get 200OK. However, when it's deployed to Azure, It does not work and I get 404 Not Found.

Local:

enter image description here

Azure:

enter image description here

What is the problem? why can't I execute an HttpTrigger?

Also, is there a way to view local.settings.json configururation in Azure? I though these settings would somehow populate from local.settings.json in Azure (like connection strings)-yet they're blank. Is there a way to show these settings in Azure?

enter image description here

Upvotes: 0

Views: 2180

Answers (3)

ShaneKm
ShaneKm

Reputation: 21308

I found the solution. My issue was that Runtime version was set to: ~1 instead of ~3. Another change I had to make for IOptions to bind is edit project, and modify these options:

<Content Include="local.settings.json">
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>

enter image description here

To make logging work: https://nuggets.hammond-turner.org.uk/2019/10/tuesday-quickie-ilogger-in-azure.html

I added this and now I see all logs fine:

{
  "version": "2.0",
  "logging": {
    "logLevel": {
      "ServiceLogger": "Information"
    }
  }
}

but all the answers from other users got me on the right path.

Upvotes: 0

freeAll
freeAll

Reputation: 82

There should be an option for azure to give you the function url. Should look something like this enter image description here

Upvotes: 1

Stephen Cleary
Stephen Cleary

Reputation: 456342

is there a way to view local.settings.json configururation in Azure?

There is no local.settings.json in Azure, hence the name "local".

You should add settings with the same names to your App Settings.

Upvotes: 2

Related Questions