marc_s
marc_s

Reputation: 755217

Making BLOB storage trigger for Azure Function configurable in Settings

When I have a timer-triggered Azure Function (v4 - running on .NET 8, isolated worker model), I have to define a CRON expression for the schedule:

[Function(nameof(TimerFunction))]
public static void Run([TimerTrigger("0 */5 * * * *")] TimerInfo timerInfo, FunctionContext context)
{
    // code
}

I can put this CRON expression into an environment variable called cronschedule, which I then specify in e.g. the Azure Portal's settings for that Azure Function - which makes it really easy to modify / update this CRON expression, and also manage multiple versions of the Azure function with separate schedules:

[Function(nameof(TimerFunction))]
public static void Run([TimerTrigger("%cronschedule%")] TimerInfo timerInfo, FunctionContext context)
{
    // code
}

This works very nicely, and I really like that.

Now I have another Azure function that needs to be triggered by a file being uploaded to blob storage. In the basic examples, the path and file name that trigger execution is always shown as a fixed string in the MS docs:

[Function(nameof(BlobFunction))]
public static string Run([BlobTrigger("sample-trigger/{name}")] string myTriggerItem, FunctionContext context)
{
    // function code
}

Can I do the same thing here, too? Can't find any hint in the docs - which makes me wonder if that feature just hasn't been mentioned in the docs, or whether it's not possible.

I'd like to have two instances of that Azure function - one for TEST, one for PROD - with different paths for the trigger

TEST:

[Function(nameof(BlobFunction))]
public static string Run([BlobTrigger("sample-trigger-test/{name}")] string myTriggerItem, FunctionContext context)

PROD:

[Function(nameof(BlobFunction))]
public static string Run([BlobTrigger("sample-trigger/{name}")] string myTriggerItem, FunctionContext context)

Right now, I end up having to change my function source code before deploying to Azure (and often times missing that crucial step, leaving me to wonder what's not working .....). Can I put that "triggering path/filename" into an Azure environment variable in the settings as well?

Upvotes: 0

Views: 91

Answers (1)

phil
phil

Reputation: 2189

I suggest you have two storage accounts: test and production. Leave your triggering path the same and just put the storage account connection string in configuration.

The other thing that might work for you is to use the Uri binding parameter. You could specify a regex in configuration and the function could check that the Uri of the triggering blob matches the regex.

Upvotes: 0

Related Questions