Azure blob triggered function only triggering on some blobs - azure

I have two blob triggers which I want to trigger on. One works and one does not!
I use Azure Storage Explorer to make sure blobs are uploaded to each blob, scanFiles will never trigger, and scanExports seem to always trigger.
Question: What can cause some blobs to not trigger an Azure function?
[FunctionName("scanFiles")]
public static async Task FilesScan([BlobTrigger("files/{newBlobName}", Connection = "BlobConnectionstring")]CloudBlockBlob newBlob, string newBlobName, ILogger log, ExecutionContext context)
{
await VirusScan(newBlob, newBlobName, log, context);
}
[FunctionName("scanExports")]
public static async Task ExportsScan([BlobTrigger("exports/{newBlobName}", Connection = "BlobConnectionstring")]CloudBlockBlob newBlob, string newBlobName, ILogger log, ExecutionContext context)
{
await VirusScan(newBlob, newBlobName, log, context);
}

I found that the issue was because one of the blobs were considered High scale, which triggers this bug and also makes the host process kill itself when run locally (see this issue)

Related

Azure function with .net core 3.1 not triggering from Queue storage

I am trying to trigger an Azure function when a new queue message is added. Both the storage account and the azure function are in the same region.
For my Azure Function, I clicked on Add, Azure Queue Storage Trigger, I gave my function a name, and the Queue name is the same name as my queue. I tried adding a new queue message, nothing is triggered.
I then tried modifying the code as the following:
using System;
[FunctionName("QueueTrigger")]
[StorageAccount("storagetestaccount1")]
public static void Run(
[QueueTrigger("queue1")] string myQueueItem,
ILogger log)
{
log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
}
But still no success. Any idea what might be causing this?
This is my first azure function so not sure what's correct and what's not.
I think the correct code is this:
public static class Function1
{
[FunctionName("Function1")]
public static void Run([QueueTrigger("queueName", Connection = "connectString")]string myQueueItem, ILogger log)
{
log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
}
}
Note
If you develop locally, you should config your azure storage connect string in local.settings.json
If you develop in azure portal, you need to config connect string in Application settings:

Azure Storage Blob Trigger is not awakening a sleeping function

This question is similar to Azure Blob Storage trigger Function not firing
However, their problem was that their Azure Function wasn't awaking immediately, giving the impression it wasn't processing triggers from Azure Blob Storage when in fact it was after 10 minutes which is exactly as the MS docs claim.
https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob-trigger?tabs=csharp
My problem is different. My blob has been sitting in the container now for 9 hours and it still hasn't been processed.
All it does is post a message onto ServiceBus.
[FunctionName("IncomingFileDetected")]
[return: ServiceBus("incoming-file-received", EntityType = Microsoft.Azure.WebJobs.ServiceBus.EntityType.Topic)]
public static IncomingFile Run(
[BlobTrigger("incoming-files/{filename}", Connection = "ConnectionStrings:MutableStorage")]
Stream contents,
string filename,
ILogger log)
{
log.LogInformation($"Detected new blob file: {filename}");
return new IncomingFile(filename);
}
No messages have appeared in the service bus.
Now, after 9 hours, I have restarted the function app and the blob was processed within about 10 minutes.
Update:
Thanks for Peter Morris's sharing, the problem comes from is service plan is d1. So first make sure you are based on the three kinds of plans: consumption plan, premium plan and app service plan. When we use azure function, even only test, we should use a consumption plan. The smallest in production is S1, which is normally used for testing.
Original Answer:
The below code works fine on my side. Even the consumption plan is no problem.
using System;
using System.IO;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
namespace FunctionApp35
{
public static class Function1
{
[FunctionName("Function1")]
[return: ServiceBus("test", Connection = "ServiceBusConnection")]
public static string Run([BlobTrigger("samples-workitems/{name}", Connection = "str")]Stream myBlob, string name, ILogger log)
{
log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
string a = "111111111111111";
return a;
}
}
}
This is my local settings:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=0730bowmanwindow;AccountKey=lti/ThmF+mw9BebOacp9gVazIh76Q39ecikHSCkaTcGK5hmInspX+EkjzpNmvCPWsnvapWziHQHL+kKt2V+lZw==;EndpointSuffix=core.windows.net",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"str": "DefaultEndpointsProtocol=xxxxxx",
"ServiceBusConnection": "Endpoint=sb://bowmantestxxxxxx"
}
}
The str is from this place:
The ServiceBusConnection is from this place:
And please notice that the blob will will not be removed from container after the azure function is triggered. Also, dont forget to create at least one subscription in your service bus topic.
All all the above also works fine after the function be deployed to azure.(The difference from local is you need to add settings in configuration settings instead of local.settings.json)

Azure Function: Http Trigger instead of Blob Trigger for more resilient operations

I have a scenario where I write some data to an azure storage blob, trigger an azure function to process the data, and write the result to another blob storage record. I've come across a weird scenarios where if the function hasn't triggered for a while(couple days) it will stop responding to the trigger unless I navigate to the azure portal and restart the function. This also happens when I use VSTS to publish the function in my CI/CD pipeline. Again, a restart is required.
To get around this, I would prefer to use an HTTP trigger where I can at least get a status code response to my request and have a better sense that my function has actually been triggered.
Here is the method for the blob trigger that is working:
[FunctionName("ProcessOpenOrders")]
public static async Task Run([BlobTrigger("%TriggerBlobPath%/{name}")]Stream myBlob, string name, TraceWriter traceWriter, [Blob("%OutboundBlobPath%/{name}", FileAccess.Write)] Stream outputStream, ExecutionContext context)
The TriggerBlobPath and OutboudBlobPath are slot setting configurations. This is important because I need the blob storage record name as a parameter so I know what to read and I use the same record name as the output.
For an HTTP trigger, I would need that name in a similar way. My question is how?
Something like this I'm guessing:
public static async Task Run([HttpTrigger] HttpRequestMessage request, [Blob("%InboundBlobPath%/{name}", FileAccess.Read)]Stream myBlob, string name, TraceWriter traceWriter, [Blob("%OutboundBlobPath%/{name}", FileAccess.Write)] Stream outputStream, ExecutionContext context)
but I get the following error:
Microsoft.Azure.WebJobs.Host: Unable to resolve binding parameter 'name'. Binding expressions must map to either a value provided by the trigger or a property of the value the trigger is bound to, or must be a system binding expression (e.g. sys.randguid, sys.utcnow, etc.).
If anyone knows how to implement an HttpTrigger in place of a blob trigger, but get the same functionality, that would be very helpful. Otherwise, if someone has an idea on how to guarantee that the blob trigger actually triggered, that would also be very helpful.
Thanks!
I think the official guidance is to use Event Grid trigger to react on blob events. See Reacting to Blob storage events and Event Grid trigger for Azure Functions.

Generic Azure Functions - Dynamic Connections

I want to create and host a azure function that would take as input "azure-storage-account-name" and "path" and run some common logic and then return a list of processed blobs in that storage account at that path. I have 20 storage accounts and I was thinking to write single azure function in same subscription to have listing capability across all of them
I went through Azure function documentation couldn't figure out if this is even possible in current offering. Any pointers would be helpful
You can use Imperative Bindings feature of Azure Functions. This is a sample code:
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, Binder binder, TraceWriter log)
{
var attributes = new Attribute[]
{
new StorageAccountAttribute("your account"),
new BlobAttribute("your folder name")
};
var directory = await binder.BindAsync<CloudBlobDirectory>(attributes);
log.Info(directory.ListBlobs().Count().ToString());
return new HttpResponseMessage(HttpStatusCode.OK);
}
If you have the correct credentials, you can use the Azure Storage REST API to get a list of containers

Azure continuous webjob (blob) triggering only once

I have an Azure webjob that has a few blob triggered functions within. I uploaded this to Azure via the Add job dialog on the portal and set it to "Run Continuously" The behavior expected was that any time a blob is added /modified to the containers specified in the blob trigger the corresponding function be called. This however does not happen.
The only way to trigger the functions (after having uploaded blobs) is to Stop the web job and restart it again.
Every time I restart the job the functions
seem to be triggered and triggered only once. Any subsequent blob updates don’t seem to trigger them again.
On the portal however the WebJob shows as 'Running' however no functions get triggered after the initial trigger.
The main function for this web job looks like this :
static void Main()
{
var host = new JobHost();
host.RunAndBlock();
}
What could be the issue ?
The trigger functions are standard blob triggered functions and work for the first time - hence I am not yet sharing that code.
UPDATE
The function signature looks like this
public static void UpdateData([BlobTrigger("inputcontainer/{env}-update-{name}")] Stream input, string name, string env, TextWriter logger)
public static void DeleteData([BlobTrigger("inputcontainer/{env}-delete-{name}")] Stream input, string name, string env, TextWriter logger)
Because of how the blob triggers are implemented, it can take up to 10 minutes for the function to be invoked.
If the function is not triggered even after 10 minutes, please share with us the function signature and the names of blobs that you are uploading.

Resources