I'm coding a C# function which is triggered by the upload of a blob. I would like to read another file in the container. How would the input binding bring the second blob?
public static async Task Run([BlobTrigger("csv/{name}.csv", Connection = "StorageConnectionAppSetting")]Stream myBlob, string name, ILogger log)
In addition to this question, how can I reference values from the local.settings.json in my code? I'm able to reference the "StorageConnectionAppSetting" on the input binding but I'm not sure how to do the same for portions of my code where I'm creating clients using APIKEYs.
Thanks!
A blob-trigger can be a single blob, but you can add an input binding to your function. In this case you can add an input binding to CloudBlobContainer by adding a reference to the storage SDK, and then read any blobs in that container.
https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob-input?tabs=csharp#usage.
Another option would be not to use input binding and read the container and its contents the way you would normally do using storage SDK. You will need to add reference to Microsoft.Azure.Storage.Blob in both the cases.
For app settings you can use System.Environment.GetEnvironmentVariable("APIKEY");, assuming APIKEY is your customer setting. Remember, local.settings.json will only be local and you will need to set these values in Azure either via Azure Portal or your CI/CD pipeline via and ARM template.
You can also use Azure functions dependency injection and inject configuration. Check the section Working with options and settings at https://learn.microsoft.com/en-us/azure/azure-functions/functions-dotnet-dependency-injection#working-with-options-and-settings
Related
I am pretty a new at azure function development
and I a not really understand how configuration for azure function, especially for local development
I need to set up some parameters at configuration and use them at my code
I have appsettings.json and local.settings.json
I added IConfiguration configuration as parameter to constructor to some my class
and try to get value by calling
_configuration["MyVar"]
but values are always null. (like it not read appsettings.json)
that is the best practice to get/set some parameters values for local test and use them after on azure side.
You can set your configuration values in local.settings.json for debugging and in the Function AppSettings in Azure Portal for when it's deployed. If you want to use a custom appsettings file, you need a FunctionStartup class.
You won't be able to configure the trigger bindings in the appsettings file, you'll have to use the Function AppSettings for that. Please see this StackOverflow post for more details.
Recommended way to read App settings in Azure functions(in App Service) is:
var value = Environment.GetEnvironmentVariable("your_key_here");
Check out this article for detailed explanation: Azure — Reading application settings in Azure Functions (ASP.NET Core)
I want to simplify deployment of my Azure Functions v3 project as much as possible.
As an example, take this function, which uses a binding expression to refer to the DoTheThingSchedule appsetting:
[FunctionName("DoTheThing")]
public async Task Run([TimerTrigger("%DoTheThingSchedule%")]TimerInfo timer)
{
// do the thing
}
For local development I can configure a value for DoTheThingSchedule in local.settings.json, but I haven't found a way to configure a default value in production, which means I'll always have to explicitly configure this setting in Azure.
Does anyone know of a way to work around this?
Azure needs you to add settings in configuration settings in azure. And it will not upload local.settings.json file to azure. But if you are using VS to publish, you can set the settings before publish:
I have a continuously running webjob that uses queue trigger. I need some data that is configured in the app.config file and i use
public static void ProcessQueueMessage([QueueTrigger("%queueName%")] Model modelMessage, int dequeueCount, [Blob("%blobStorageName%")] CloudBlobContainer cloudBlobContainer, string id)
{
// some code here
var setting = ConfigurationManager.AppSettings["setting"];
// some code using setting
}
to get the data into setting into the variable. But all of this is in Azure webjobs 2.1 sdk.
But from 3.x we only have appsettings.json file. how do i get the setting from json file into inside the trigger method
Used dependency injection to inject HostBuilderContext to the constructor and got the config from there.
I have a method called ReadFileData(string blobStorageFilePath) in my .NET Web API project. This method reads the text content from Azure Blob file. The azure blob storage file path is passed via the parameter in this method. Till now a client application (web) was calling this method to read file data but now I have to automate this process.
So, is it possible to call this web API method (by some way) whenever a new file is added to azure blob storage automatically? So this way there will be no need of any client application.
Which approach should I use to implement this process?
Any working example will be appreciated.
You can add a webjob to your Azure app service and install the Azure Webjobs SDK. Then you can easily trigger your read with a simple declarative blob trigger
https://learn.microsoft.com/en-us/azure/app-service-web/websites-dotnet-webjobs-sdk-storage-blobs-how-to
public static void CopyBlob([BlobTrigger("input/{name}")] TextReader input,
[Blob("output/{name}")] out string output)
{
output = input.ReadToEnd();
}
https://learn.microsoft.com/en-us/azure/azure-functions/functions-create-storage-blob-triggered-function
You can create a function triggered by Azure Blob storage. Please see the link for the complete example
I'm having azure worker role project. below is a code from my configuration (.cscfg).
c# (FLAG = 1;)
Through c# code i want to change this value.
Is there any way for dynamically changing value of an azure service configuration?
Please instruct me how to do it.
Simple answer is that you can't change the value of just one setting through code as RoleEnvironment class only exposes a Get method and there's no Set method.
A convoluted approach would be to invoke Service Management API, read the configuration settings file using Get Deployment operation, change the XML file and the call Change Deployment Configuration operation. Not sure how this would work out if you're changing the configuration from the same role though.