I have looked at the Azure functions documentation but couldn't quit find answer to my question and hence I thought I asked the wider user community.
We have a single Azure subscription with multiple resource groups for our different environments, so one group for dev, one for test and one for prod.
We have developed multiple Azure functions in dev and would like to use CI/CD to deploy to test and prod.
However, doing this manually Azure complains that the name of the function app already exists which is weird because that would imply that the function app name must be unique to the subscription or globally across Azure? Does that mean you need to name your function apps func-dev, func-test etc? That seems very ugly.
How have you managed to solve this?
azure function name has to be globally unique (not just in your subscription), because the name would be like:
functionName.azurewebsites.net
so you cannot have a function with name functionName if you already created one, because the dns name for that is occupied.
you can use subfunctions to work around that, so create a subfunction called dev, test, and prod inside the function and call those
Function App, as any App Service application, has to have globally unique name:
Naming Conventions -> Compute.
Indeed, it's typical to include your environment into the App name.
Function names have to be unique within a single Function App, but may repeat in different apps.
Related
I have developed a number of JavaScript functions that all get deployed to an Azure Function App. I have two different code sets intended for two different Azure FAs. Unfortunately, when the FAs were created they were not given a meaningful name, and instead are just a random string of letters and numbers.
I primarily deploy my code to Azure from within VSCode, and that seems to work fine. However, I have a strong concern that one day I will deploy one set of functions to the wrong FA, which would of course cause big problems.
Is there anywhere that I can define a list of "allowed" function apps, so that if I were to attempt deploying the code to another FA it would fail? Or is there another method to achieve a similar result?
As of right now, I can deploy any codebase to any FA.
To prevent deploying code to the wrong function:
There are few methods for restricting deployment to only particular Function Apps and preventing deployment to undesired Function Apps.
Use Deployment slots:
As detailed in MSDoc, You can choose a deployment slot for a function app which has a different URL than function app.
Instead of executing immediately in a production environment, you can test any fixes or incorrect deployments in a different deployment slot before it goes live by deploying it into a secondary deployment slot.
Because it is your production environment slot, your users will be accessing your original Function App.
How to work with Deployment Slots:
Goto Function App and you will find Deployment slots under deployment and then Add a slot as described in the below image:
You can also create a deployment slot using Az CLI command az functionapp deployment slot.
Use below format:
az functionapp deployment slot create --name <Functionapp> --resource-group <ResourceGroup> --slot "slot1"
Use Deployment Scripts:
When you deploy your code, you can specify a deployment script, which can be a CLI or PowerShell script.
You can create a deployment script that verifies the target Function App's name and fails if it does not match one of the given Function Apps.
Goto Azure Portal and search for Deployment Scripts to work with this.
Is it possible to lookup the application name for an Azure app as it runs, i.e., get the information about that is displayed in the Azure portal? In the example below, I'd want something to tell me from within the application that I am running sitemap-prod-eastus.
I've been looking at the Azure Context object but not seeing what I need. There is an invocation ID, a name for the function, a directory - not the info in this window.
Maybe this can be done through Azure Application Insights?
I am working in Node JS.
I've not seen anything that would expose this to a function app. That said, there is one sort of workaround that you could do which would work - go to the Configuration blade for the function app, Application settings tab, and add a configuration key like function_name and set its value to the name of your app. Your app could then just read it out of configuration.
It's an extra step, but if you're doing it with something like ARM or Terraform, it's just another configuration entry with a variable you already declared to set up the app in the first place.
Answering my own question: Azure provides WEBSITE_SITE_NAME in the runtime environment that matches the name of the function app.
With my limited experience on Azure cloud, I am having the impression that Azure Function App requires a globally unique name. It seems true that if you test creating a new Function App through Azure Portal.
However, I have seen in a recent project that same function app (with same name) with different settings of course, being deployed to multiple resource groups under same subscription.
Can anyone explain? I am struggling to find an official answer from Microsoft sites.
Many thanks,
W
You are right, Azure function app name must have Globally unique name.
When you create Azure function app, you specify the name which becomes part of URL <azurefunctionname>.azurewebsites.net
Valid characters for Azure function app name are a-z (case insensitive), 0-9, and -.
https://learn.microsoft.com/en-us/azure/azure-functions/functions-create-function-app-portal#create-a-function-app
my project has 3 Service bus and 2 HTTP triggers. (5 functions)
How to deploy each function in a separate Azure function app?
The easiest way is to copy the code of the trigger you created before and create a new function app with a single trigger, then put the code into it(Deploy function app must be based on function app, and the function app should correspond to the project on local.).
The more complicated method is, first make sure the structure of your function app(this needs to check the language. function app has two types, one type is a scripting language and another type needs to be compiled.) For this, you can have a check of this official doc:
https://learn.microsoft.com/en-us/azure/azure-functions/supported-languages
Go to the language you are using and search the folder structure(your deployment structure should like the 'folder structure' in the doc. What needs to pay attention to is for the language like C# and java, you need to deploy the compiled files. Azure can't identify the source files.) Then you just need to imitate the structure and deploy based on this structure.
'Deploy' operation is just a upload operation, so you just needs to upload the files in specific structure, then azure can identify it.
Finally, you can use zip deploy to deploy your function app(Or to say deploy a project, a structure that azure can run must first run success on local.).
az webapp deployment source config-zip --resource-group <group-name> --name <app-name> --src clouddrive/<filename>.zip
(Above command is been used by some Integrated Development Environment, such as Visual Studio.)
I suggest you to use the first way, because it is simpler.
I am trying to use a template to deploy a managed Kubernetes cluster (AKS). My problem is that the template has a parameter aadSessionKey that I seem to be unable to locate.
I assume the expanded name of the parameter is Azure AD SessionKey. When I look in the portal, I can see that my Azure AD has a Name, Application ID and Object ID, but nothing that looks like a session key, nor a way to generate such a thing.
I am using a free trial account if that matters.
Can you try entering any random value and try deploying it. It seems like this is system generated value which is not to be filled by clients. This has been present in template for some other reason.
Ref - https://twitter.com/ashtonkj/status/1196384865672925184