Deploying same Azure cloud function for each environment - dev, qa, prod - azure

Have a function app with single cloud function in it. The cloud function is triggered by an HTTP call and pushes the payload to a Azure service bus queue. What needs to be done is, as part of automated deployment, would like to have few variables configured per environment -
Function Name
Queue Name
Queue Connection String
Deployment is to be done using Azure DevOps. Function code is also on Azure DevOps repository which will have branch for each environment, so will need function with different function name for eg - Dev_Function, QA_Function,etc since it needs to connect to corresponding environment queue. Also aware that variables can be configured using App Settings on Azure portal. Any help/insights appreciated!

i think you could keep the function name as it is and change make the Queue name and Connection string to be pickup from Azure function app service configuration.
[FunctionName("SendEmailFunc")]
public static async Task SendEmailFunc([QueueTrigger($"%{FuncAppConstants.Queue.EmailQueueName}%")] EmailMessage emailMessage)
{
}
you can get the queue name at runtime by using this
[QueueTrigger($"%prod_queue_name%")]
and configuration will just look like below in the local.setting.json
"prod_queue_name": "test-email-queue"
and similarly in the Azure function app configuration
And same can be done for the connection string

Related

How to set value for EventHub and AzureWebJobsStorage

I have created an event hub and storage account in the Azure portal and written an azure function with an eventhub trigger to trigger the function.
To run this function locally, I set the "AzureWebJobsStorage" and "EventHubconnectionstring" in local.settings.json and this works fine.
If I deploy this function to azure portal, how can I set this "EventHubconnectionstring" and "AzureWebJobsStorage" values ? does it picked up automatically?
When you deploy it from Visual Studio the values become null. Then you need to open Configuration section in function app and enter those values there as below:
If you deploy using Vs code the values will be reflected in configuration section.
If you face the issue as empty connection string, then you need to add it in Configuration section then save it.And you should do the same for event hub connection string.
References:
Storage account connection string does not exist - deploying Queue storage trigger for Azure Functions - Stack Overflow

Any way to concatenate two Application setting in Configuration - Azure Function app

In Azure Function App, I have added two application settings using the Configuration tab. The first Application setting is fetching the SAS token from the Azure Key vault using #Microsoft.KeyVault(SecretUri=##). The other application setting is the endpoint URL. Now I have to concatenate these two variables and use in connection parameter in HTTP and Queue Trigger.
For example, Below StorageConnectionAppSetting will be the key that will have concatenated value.
public static async Task Run([QueueTrigger("myqueue-items", Connection = "StorageConnectionAppSetting")] string queueItem, ILogger log)
Is there any way this concatenation can be done in the Application setting itself.
This isn't currently possible. Even if you were to customize configuration using DI, it won't work for triggers when deploying to the consumption or premium plans as mentioned at the end of the docs.

Does EventGridTrigger wors in App service plan and ASE?

I have an Event Grid Trigger Azure function deployed to a function app which is in an ASE. I have created an event grid subscription with this function as an end point. The purpose of this subscription is to call this function once a blob file is created.
When I placed the file in the location, the event is supposed to call the function but I see the event is undelivered.
How can I resolve the issue?
I found this in Azure documents :
" When your function app runs in either an App Service plan or an App Service Environment, you can use non-HTTP trigger functions. For your functions to get triggered correctly, you must be connected to a virtual network with access to the resource defined in the trigger connection. "
Maybe you can refer to this article.enter link description here
I have created an eventgrid subscription that writes the event to a queue whenever a file is created in blob. I have modified exiting EvenGridTrigger function to QueueTrigger function. Both storage account and function app are in same vnet.

Azure Function EventHubTrigger Attribute not finding event hub name

I am having an issue where my event hub name is not found when I publish my function to a function app (It works fine locally, if I just run it in VS2017). I am recieving the following error on the published function in the azure portal when I open the function.
This is the attribute on my Run method.
public static void Run([EventHubTrigger("%eventHubName%", Connection = "eventHubConnection")]string data, TraceWriter log)
Now if I don't include the %'s wrapped around the eventHubName, when I run it locally it will say that it can't find the eventhub (Using the eventHubName string literally instead of looking into the local.settings.json like the connection string), but it will work when it is published. I am wanting to avoid putting the actual name in the attribute as different environments will have unique event hub names.
Azure Functions will use the local.settings.json file when you are developing locally. When your Function App is running on Azure, it will read the values from the Application Settings.
Using the %zzz% is the correct way to read settings, so this makes me question if you have a setting called eventHubName in Application Setting when you deploy to Azure.
https://learn.microsoft.com/en-us/azure/app-service/web-sites-configure

Azure WebJobs SDK ServiceBus connection string 'AzureWebJobsAzureSBConnection' is missing or empty

I created an Azure Function App in Visual Studio 2015. The App has a trigger for service bus queues. The app works perfectly when I run it locally. It is able to read the data from the Service Bus queue (configured via a variable named AzureSBConnection) and log it in my database.
But it gives me the following error when deployed in Azure:
Function ($ServiceBusQueueTriggerFunction) Error: Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.ServiceBusQueueTriggerFunction'. Microsoft.Azure.WebJobs.ServiceBus: Microsoft Azure WebJobs SDK ServiceBus connection string 'AzureWebJobsAzureSBConnection' is missing or empty.
Note that my connection is called AzureSBConnection and not AzureWebJobsAzureSBConnection. Also, the connection works locally. And finally, the deployed file looks exactly like the local file.
The Visual Studio structure looks like the following:
The function.json file has a bunch of settings as shown below:
Then in the Appsettings.json file, I have the following:
For deploying, I FTPed the files to the D:\home\site\wwwroot location for my Function App in Azure. The final structure in Kudu looks like:
And if I go inside my function folder:
Here is the deployed function.json:
And here is the deployed appsettings:
The deployed json files are exactly the same as the local files. But the deployed version is erroring out because of the missing AzureWebJobsAzureSBConnection. What am I doing wrong?
Only environment variables are supported for app settings and connection strings.
You need to make sure that the environment variable AzureWebJobsAzureSBConnection is set on your Function's app settings in the portal:
and then once there, you need to add the AzureWebJobsAzureSBConnection variable with the proper connection string:
and then you can access this via code by:
Environment.GetEnvironmentVariable(name, EnvironmentVariableTarget.Process);
This will obtain the value from either the appsettings.json or the environment variable depending on where the function is being executed from, (local debugging or deployed on Azure)
It is able to read the data from the Service Bus queue (configured via a variable named AzureSBConnection) But it gives me the following error when deployed in Azure:
After you deployed your application to Azure Function, your application will read the connection string from environment setting. Currently, connection settings in appsettings.json will not update environment setting automatically. We could click [Configure app settings] button as #flyte mentioned to check whether the connection string is configured successfully. If not, you could add it manually in app setting box.
Note that my connection is called AzureSBConnection and not AzureWebJobsAzureSBConnection
Please go to [Integrate] page to check whether the [Service Bus connection] is configured successfully. If not, you could reset it by clicking the [new] link.

Resources