Azure Functions v1 timer triggered function cannot start due to Windows Platform FIPS issue - azure

I'm trying to develop a function app that uses a timer trigger and I'm getting an issue with the Windows Platform FIPS that prevents the timer-triggered function to start locally. Here's the code that's causing the error (it's the default timer-triggered function):
using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
namespace FunctionApp1
{
public static class Function1
{
[FunctionName("Function1")]
public static void Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, TraceWriter log)
{
log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
}
}
}
When I try to run this function in func.exe, it produces the following error:
The listener for function 'Function1' was unable to start. mscorlib: Exception has been thrown by the target of an invocation. mscorlib: This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms.
This exact code works on another dev environment that I have access to. What do I need to do to fix these Windows Platform FIPS issues so that the timer trigger will run?
Thanks!

If your environment does need this FipsAlgorithmPolicy somewhere, disable it for Azure function only.
In File Explorer, open %localappdata%\AzureFunctionsTools\Releases\1.4.0\cli\func.exe.Config, add <enforceFIPSPolicy enabled="false"/> under <runtime> element. Note that in this way, you have to repeat this step once new function cli is released.
Similarly, if you use Storage Emulator locally, open C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe.config, add <enforceFIPSPolicy enabled="false"/> under element.
Else just disable FipsAlgorithmPolicy for your computer.
In search box or right click on Start button and click Run, input regedit to open Registry Editor.
In address bar(View>Address Bar), navigate to Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\FipsAlgorithmPolicy.
Double click on Enabled, change Value data to 0.

Related

Azure Timer trigger is not working in .net 5 isolated function app

Azure Timer trigger is not working in .net 5 isolated function app with the CRON expression to get triggered for every minute.
This is working fine if we run that in local visual studio.
public static class NotificationScheduler
{
[Function("NotificationScheduler")]
public static void Run([TimerTrigger("1-2 * * * * *")] MyInfo myTimer, FunctionContext context)
{
var logger = context.GetLogger("NotificationScheduler");
logger.LogInformation($"Notification Scheduler trigger function executed at: {DateTime.Now}");
//logger.LogInformation($"Next timer schedule at: {myTimer.ScheduleStatus.Next}");
}
}
As per your ask I have run the function in my local environment and it is working fine for me below is my code for reference make changes accordingly on your environment.
Created Function App in Azure Portal
2. Below is the Code which I have Used in function App
Function1.cs
using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
namespace KrishFuncTimerTriggerApp
{
public static class Function1
{
[FunctionName("Function1")]
public static void Run([TimerTrigger("0 * * * * *")]TimerInfo myTimer, TraceWriter log)
{
log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
}
}
Then I went to Code+Integration and when I did a Test Run my function app ran every minute as per my logic
As per the below Image .Net isolated function is not supported for editing in Azure Portal.
Also, try to check your SDK version as per this SO and blog if you are using SDK version "6.0.100-preview.7.21379.14" as it is in Preview could be the reason why your function app is not working, if that is the case then try to downgrade your function app.
Also Check the Cron expression link for further details

Azure Functions with trigger timer don't show logs under Monitor

I'm testing my Azure Functions and facing a funny problem. I want to see if a function was running and the result. I'm opening the function and then my function called getTokenRefresh. Apparently, this function has never started.
After a couple of hours, I decided to open Application Insights. Surprise! All logs are there.
If I run a function from the portal and open again monitor and click on the Logs tab, I don't see any logs. Again I can find everything only in Application Insights.
Another interesting thing is other functions in this Azure Functions, show me all details (believe me is the same function).
In the code point of view, I'm using dependency injection in all functions like:
public class GetTokenRefreshTimer
{
private ILogger _log;
public GetTokenRefreshTimer(ILogger<GetTokenRefreshTimer> log)
{
_log = log;
}
[FunctionName("getTokenRefreshTimer")]
public async Task Run([TimerTrigger("0 */20 * * * *")]TimerInfo myTimer)
{
_log.LogInformation("GetTokenRefresh starts");
}
}
The logs of azure function is fragile. So sometimes you can not see the logs, but this doesn't mean the azure function is not run.
If you want to know the function is running you need to go to the kudu of your azure function and see the logs file of your function app.(The logs in Application Insights is coming from this place.)
The logs file is in the place:
Open your brower and go to https://yourfunctionappname.scm.azurewebsites.net/DebugConsole, and then click into LogFiles/Application/Functions/Function/yourtriggername . You will find the log file in this place.

Whats is the difference between 'Settings.job' and 'TimerTrigger' in Azure WebJobs SDK 3.0

There are many tutorials using the following code to create a Webjobs via the WebJob SDK 3.0 library. Specifically 'TimerTrigger'
public void DoSomethingUseful([TimerTrigger("0 */1 * * * *", RunOnStartup = false)] TimerInfo timerInfo, TextWriter log)
{
// Act on the DI-ed class:
string thing = _usefulRepository.GetFoo();
Console.WriteLine($"{DateTime.Now} - {thing}");
}
The above example should run this method as a webjob every 1 minute. However this doesn't work.
I have managed to get the webjob to work when including a setting.job file.
setting.job: { "schedule": "0 */1 * * * *" }
My question is what is the different between these two?
Update:
Please go to the azure webjobs log, then you can see it actually runs as per the timerTrigger defined by SDK(even though the Schedule is n/a, and settings.job is blank, it does not matter):
In short, When using webjob sdk 3.x, you can use TimerTrigger attribute to run the function as per the time you defined. Without using webjobs SDK(like use .zip file or publish a console project from visual studio), you can use setting.job to defined timer instead of TimerTrigger attribute.
1.When you're using webjobs SDK 3.x for timer trigger, you should add this line of code: config.AddTimers(); .
Here are my code using webjobs SDK 3.x(it's a .net core 2.2 console project created in visual studio):
The packages with latest version: Microsoft.Azure.WebJobs / Microsoft.Azure.WebJobs.Extensions / Microsoft.Extensions.Logging.Console
The code in Program.cs:
class Program
{
static void Main(string[] args)
{
var builder = new HostBuilder()
.ConfigureWebJobs(config =>
{
config.AddTimers();
config.AddAzureStorageCoreServices();
})
.ConfigureLogging((context, b) =>
{
b.AddConsole();
}
)
.Build();
builder.Run();
}
}
Then create a new file, like SayHelloWebJob.cs, and code in it:
public class SayHelloWebJob
{
public void ProcessCollateFiles([TimerTrigger("0 */1 * * * *", RunOnStartup = false)]TimerInfo timerInfo,TextWriter writer)
{
writer.WriteLine("hi, it is a testing running");
Console.WriteLine("test");
}
}
Note that in the appsettings.json file, add your storage connection string, like below:
{
"AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=xxx;AccountKey=xxx;EndpointSuffix=core.windows.net"
}
Then run the project, you can see the function is triggered as per 1 minute:
2.For settings.job, eg. if you're just creating a console project, and does not use the webjobs sdk. Since you're not using webjobs sdk, you cannot use the timerTrigger attribute. At this moment, you can include the settings.job file(in it's property, set "Copy to Output Directory" as "copy if newer") in this project and configure the scheduled timer like you did in your post. After publish as webjob(from visual studio, when publish, select "Webjob run mode" as "run on demand"), it can run as per the schedule you defined in settings.job.
I have been struggling with the same problem. Here is my understanding after longer research.
There are two kind of Webjobs:
triggered
continuous
Triggered one has to be triggered manually or can be triggered by App Service as per CRON expression schedule provided in setting.job. These jobs are not present in memory once not running.
Continuous one runs always, so the process exists in memory all the time. You can schedule it using Webjobs SKD TimeTrigger attribute.
You will also notice difference between these two Webjob types in the Dashboard.
For triggered Webjobs you will see on top level jobs runs then functions invoked and eventually invocation details.
For continuous Webjobs this will be functions invoked and eventually invocation details. Job runs are missing as this is just one long running job.
Check App Service / Process explorer under Kudu w3wp process to see Webjobs processes running.
Note that continuous and triggered Webjobs have to be started in different way in Main method where you provide the configuration. All comes configured when Webjob of specific type is added via Visual Studio.
This is based on WebJobs 2.x.
My recommendation is
for periodical (e.g. once per few hours, days) jobs use triggered
ones, job when not running will not consume resources,
for more frequent jobs use continuous ones with TimeTrigger
attribute, it will consume resources all the time but will not need
extra time for start-up.

The binding type 'serviceBusTrigger' is not registered error in azure functions c# with core tools 2

I open a fresh new azure functions project, my packages are:
Microsoft.Azure.WebJobs 3.0.0-beta4
Microsoft.Azure.WebJobs.ServiceBus 3.0.0-beta4
Microsoft.NET.Sdk.Functions 1.0.7
NETStandardLibrary 2.0.1
I use servicebustrigger and my function code is basic:
public static class Function1
{
[FunctionName("OrderPusherFunction")]
public static Task Run([ServiceBusTrigger("orders","orderpusher", Connection ="ServiceBus")]
string myQueueItem, TraceWriter log)
{
log.Info($"C# Queue trigger function processed: {myQueueItem}");
return Task.CompletedTask;
}
}
I also have:
Azure Functions Core Tools (2.0.1-beta.22) and Function Runtime Version: 2.0.11415.0
When i run, i get "The binding type 'serviceBusTrigger' is not registered" error, and the function does not get triggered. Anyone has an idea? This looks to me as a basic setup..
Basically, in v2 ServiceBus trigger was moved out of the default installation into Extensibility model. You need to register Service Bus binding as an extension as per Binding Extensions Management.
Unfortunately, this is all work-in-progress, as there is a number of issues for Service Bus binding:
Migrate ServiceBus Extension to .NET Core - "Done", but see the comments for which problems still exist
Build failure after installing ExtensionsMetadatGenerator into empty v2 app prevents VS tooling from registering the extension properly
Extensions.json is not updated when "extension install" CLI command executed for service bus extension for CLI issue
My advice would be to stick to v1 for now.

Scheduled web job confusing about schedule

I have a web job that needs to run every day at 1am.
My settings.job is configured like this:
{
"schedule": "0 0 1 * * *",
"is_singleton": true
}
I have function declared in the Functions.cs
namespace Dsc.Dmp.SddUpgrade.WebJob
{
using System;
using System.IO;
using Microsoft.Azure.WebJobs;
public class Functions
{
public static void TriggerProcess(TextWriter log)
{
log.Write($"C# Timer trigger function executed at: {DateTime.Now}");
}
}
}
I am getting the following logs:
[09/28/2017 12:02:05 > 9957a4: SYS INFO] Status changed to Running
[09/28/2017 12:02:07 > 9957a4: INFO] No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).
As I read the documentation, some people are using a function signature like this:
public static void TriggerProcess([TimerTrigger("0 0 1 * * *")] TimerInfo timerInfo, TextWriter log)
However, this does not seem logic to me, because a have already configured my web job to by scheduled in the settings.job.
What am I missing here?
If you use a settings.job file to schedule your WebJob, your logic should go in the Program.cs's Main function. You can ignore the Functions.cs file if you go this route. This is great for migrating a console app into a WebJob and scheduling it.
The TimerTrigger is a WebJob extension. It's useful because it's possible to have multiple methods in Functions.cs, each with a separate TimerTrigger that executes on a different schedule. To use these, your WebJob needs to be continuous.
You need to put your logic in Program.cs.
The runtime will run your WebJob by executing the executable, running the Main method in Program.cs.
You seem to be missing the [FunctionName("TriggerProcess")] attribute in the function definition, that´s why you´re getting the "job not found" error.

Resources