I've created and successfully tested a Function App that requires the .net Framework because of a legacy library, and is set to use run-time version ~1. I'm looking for the Invoke Url and code, to help automate deployment.
Following this MS article and using the azure-functions-core-tools v2 (npm i -g azure-functions-core-tools#^2), I can see the Invoke Url when publish is called with the --verbose option.
However, because of the .net Framework requirement and run-time version ~1, we're bound to azure-functions-core-tools v1 (npm i -g azure-functions-core-tools#^1) (see here). Executing any of the commands from func azure functionapp does’t include the Invoke Url. The --verbose option is not available.
>func azure functionapp publish <MyApp>
Getting site publishing info...
Publish C:\<MyProject> contents to an Azure Function App. Locally deleted files are not removed from destination.
Creating archive for current directory...
Uploading archive...
Upload completed successfully.
Same for list-functions
>func azure functionapp list-functions <MyApp>
Functions in <MyApp>:
FunctionOne - [httpTrigger]
FunctionTwo - [httpTrigger]
I haven't tried ARM yet.
Is there a way to obtain the Invoke Url for Function Apps on run-time version ~1?
I get the Invoke Url and the code with the following Azure CLI commands:
FUNCTION_CODE=$(az functionapp function keys list -g ${SOLUTION_NAME} -n $FUNCTIONS_NAME --function-name DPSCustomAllocationFunction --query "default")
FUNCTION_CODE=$(echo "$FUNCTION_CODE" | tr -d '"') #Remove "" from result
FUNCTION_URL=$(az functionapp function show --function-name DPSCustomAllocationFunction --resource-group $SOLUTION_NAME --query "invokeUrlTemplate" --output tsv --name $FUNCTIONS_NAME)
FUNCTION_URL=$(echo $FUNCTION_URL|tr -d '\r\n') #Remove breaklines from result
INVOKE_FUNCTION="$FUNCTION_URL?code=$FUNCTION_CODE"
Yo could use the REST API to get it:List Function Secrets, it will response the secret and triggerUrl.
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/functions/{functionName}/listsecrets?api-version=2016-08-01
Also you could implement it with the PowerShell GetFunctionInvokeUrl to do it.
You can do this with Azure CLI:
az functionapp function show
az functionapp function show --function-name MyFunction --name MyApp --resource-group MyResourceGroup --query "invokeUrlTemplate" --output tsv
Related
I have 2 different function apps and deployment scripts. The first app (functionApp1) uses the az cli, and the second one is being written to use the new AZ Powershell modules.
I thought I wouldn't be impacting the az cli solution by installing/setting up the latest powershell cmdlets but I think functionApp1's deployment is broken since installing the new Az Powershell tools.
When I run the az cli deployment script for function App 1, it dies while trying to publish the application. The error message says:
You're trying to use v4 tooling to publish to a non-v4 function app
(FUNCTIONS_EXTENSION_VERSION is set to ~3). You can pass --force to
force update the app to v4, or downgrade tooling for publishing.
Code
In case it helps, here are some snippets of code from the deployment script for functionApp1 The following logic to create a resource group, application insights, and a storage account all works:
az login --service-principal --username $CLIENT_ID --password $SECRET --tenant $TENANT --allow-no-subscriptions
az account set --subscription $SUBSCRIPTION_ID
az group create -n $RESOURCE_GROUP_NAME -l $RESOURCE_LOCATION
az deployment group create --resource-group $RESOURCE_GROUP_NAME --template-file (Join-Path $PSScriptRoot "./resources/function1App.json")
Next I grab information from the new resources I created above, and I update my local.settings.json file. This also still works:
func settings add FUNCTIONS_WORKER_RUNTIME dotnet #explicitly set this.
#auto-update the local.settings.json file with connection string
func azure storage fetch-connection-string $storageAccount.name
#grab contents of local settings file.
$data = Get-Content 'local.settings.json' -raw | ConvertFrom-Json
#logic to update local settings.
Lastly I try to publish the functions in azure using my local settings file. And this is the part that is no longer working:
$functionDeploymentResult = func azure functionapp publish $FUNCTION_APP.name --publish-local-settings -i --overwrite-settings -y
But the error message I'm getting is this:
You're trying to use v4 tooling to publish to a non-v4 function app (FUNCTIONS_EXTENSION_VERSION is set to ~3).
You can pass --force to force update the app to v4, or downgrade tooling for publishing.
I tried to add the --force option and while it gets rid of the error message, when I try to actually run my test "hello world" function in azure, I see the following error message:
Microsoft.Azure.WebJobs.Script: One or more loaded extensions do not meet the minimum requirements. For more information see https://aka.ms/func-min-extension-versions.
ExtensionStartupType AzureStorageWebJobsStartup from assembly 'Microsoft.Azure.WebJobs.Extensions.Storage, Version=4.0.3.0, Culture=neutral, PublicKeyToken=asdfasdfasdf' does not meet the required minimum version of 4.0.4.0. Update your NuGet package reference for Microsoft.Azure.WebJobs.Extensions.Storage to 4.0.4 or later.
AZ CLI VERSION
PS C:\Users\me\Documents\src\functionapp1> az --version
azure-cli 2.30.0 *
core 2.30.0 *
telemetry 1.0.6
Python location 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe'
Extensions directory 'C:\Users\me\.azure\cliextensions'
Python (Windows) 3.8.9 (tags/v3.8.9:a743f81, Apr 6 2021, 13:22:56) [MSC v.1928 32 bit (Intel)]
Legal docs and information: aka.ms/AzureCliLegal
You have 2 updates available. Consider updating your CLI installation with 'az upgrade'
Please let us know how we are doing: https://aka.ms/azureclihats
and let us know if you're interested in trying out our newest features: https://aka.ms/CLIUXstudy
.vscode/settings.json
{
"azureFunctions.deploySubpath": "src/bin/Release/netcoreapp3.1/publish",
"azureFunctions.projectLanguage": "C#",
"azureFunctions.projectRuntime": "~3",
"debug.internalConsoleOptions": "neverOpen",
"azureFunctions.preDeployTask": "publish (functions)"
}
I'm presently trying to do some research on how / what specifically to downgrade but any tips / suggestions would be appreciated.
Azure PowerShell does not interfere with Azure cli installation.
Based on the error message, it looks like the version of the Azure function tools you are using is v4 but the function app that you have deployed is v3 (likely defined so in the ARM template that you are using).
When I try to deploy an Azure Function to the cloud using... func azure functionapp publish appName --build remote --publish-local-settings
...I receive the following error
Getting site publishing info...
Remote build is a new feature added to function apps.
Your function app appName does not support remote build as it was created before August 1st, 2019.
Please use '--build local' or '--build-native-deps'.
For more information, please visit https://aka.ms/remotebuild
EVEN THOUGH THE APP WAS LITERALLY JUST CREATED IN AZURE PORTAL.
System:
- Running VS Code on Ubuntu 18.04
Steps to reproduce:
Create a new Function App (and support resources) using az cli
Python runtime
Consumption plan
StandardV2 Storage plan
AppInsights
Create new Function (scaffolding) using VS Code Azure Functions extension
Create __init__.py and configure local.settings.json
Open a terminal; cd to Function folder
Run func azure functionapp publish appName --build remote --publish-local-settings
Fails everytime with the message above
Tried so far:
- Substituting --build local.
- Looks like it wants to work, but fails with error
There was an error restoring dependencies. ERROR: cannot install cryptography-2.9.2 dependency: binary dependencies without wheels are not supported when building locally. Use the "--build remote" option to build dependencies on the Azure Functions build server, or "--build-native-deps" option to automatically build and configure the dependencies using a Docker container. More information at https://aka.ms/func-python-publish
Not going to try:
- --build-local-deps because I don't want a docker instance for my Function App
Please advise. This is painful at this point.
In my case, I was provisioning an azurerm_linux_function_app with terraform and got this error. The error turned out to be caused by me forgetting to specify the storage_account_access_key setting. The docs even mention
One of storage_account_access_key or storage_uses_managed_identity must be specified when using storage_account_name.
But terraform does not actually check that when applying your configuration, resulting in a cryptic error message much later in the process.
Here is what was found today:
I initially created the Function App Storage Account with...
# Create a Function App Storage Account
az storage account create \
--name $fa_storage_name \
--resource-group $rg_name \
--access-tier Cool \
--default-action Deny \
--kind StorageV2 \
--subscription $az_sub
--location $az_loc \
--sku Standard_LRS
Changed this to...
# Create a Function App Storage Account
az storage account create \
--name $fa_storage_name \
--resource-group $rg_name \
--location $az_loc \
--sku Standard_LRS
...and was able to get past that error. The way I stumbled onto this was using the --buld local flag. It gave me a MUCH MORE ACCURATE error. Something along the lines of Check your storage account dude.
(thank you Marcelo!)
I'm trying to create Web App which is just having a Static HTML. I'm following this link https://learn.microsoft.com/en-us/azure/app-service/app-service-web-get-started-html. But when I execute the following command
az webapp up --location westeurope --name .
Got the error - " Could not auto-detect the runtime stack of your app" .
I tried the following, but added the --html flag at the end of the az webapp up command to bypass auto detection:
mkdir quickstart
cd quickstart
git clone https://github.com/Azure-Samples/html-docs-hello-world.git
cd html-docs-hello-world
az webapp up --location westeurope --name azurewebapptest123 --html
That forces HTML. In the help for the command it implies auto-detection works for a bunch of language, but not for static HTML.
I just tried following the steps mentioned in the documentation. Works for me.
mkdir quickstart
cd quickstart
git clone https://github.com/Azure-Samples/html-docs-hello-world.git
cd html-docs-hello-world
az webapp up --location westeurope --name azurewebapptest123
I have tried the similar steps using the sample repo and was able to reproduce it.
Here is the version:
It's a known bug for Azure CLI 2.0.78 and team is working on it, Which you can track it here:
https://github.com/MicrosoftDocs/azure-docs/issues/43633
Work around of this issue is to use the older version of Azure CLi e.g. 2.0.75 * for deploying the solution.
Hope it helps.
Try to manually include a web.config file and/or select the stack on General Settings:
If you have no backend, the best option to host a static site is through Azure Storage:
https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blob-static-website
I had the same problem. I solved it by using the flag --html to define explicitly the runtime according to the documentation of the runtime detection. https://github.com/Azure/app-service-linux-docs/blob/master/AzWebAppUP/runtime_detection.md
So, the solution is the following line of code:
az webapp up --location westeurope --name <name> --html
N.B: I used Azure cloud shell.
Make sure you're running the command "az webapp up --location westeurope --name" from your application root, ie inside 'html-docs-hello-world' folder.
at end of az webapp command you have give run time stack
if you are using an html page then --html you must give
Ex: az webapp up --location westeurope --name az204samplewebapphtml1 --html
To overcome this error you will need to:
cd {directory}
pip freeze > requirements.txt
The file does not need to have anything just needs to exist as azure looks for the files presence when running the deployment
I'm not able to create the azure function in python which can be used to run python script on PowerApps.
I've tried it on command prompt and also on a visual studio in the app got created but I was not able to deploy it.
Is it possible to automate the execution of a Python script using Microsoft Flow?
I'm using this link to create the azure function
(.env) C:\Users\PAhire2\MyFunctionProj>az functionapp create --resource-group myResourceGroup --os-type Windows --consumption-plan-location westeurope --runtime python --name NewApp --storage-account 1234store
usage error: Currently supported runtimes (--runtime) in windows function apps are: dotnet, node, java, powershell.
This is the error message I'm getting
You get this error cause the python function only could be created on the Linux OS on Azure, so just change your os-type to Linux, it will be success.
az functionapp create --resource-group mygroup --os-type Linux --consumption-plan-location westeurope --runtime python --name pythonfunctiontest --storage-account mystorageaccount
I test with Azure Cloud Shell and it works. Hope this could help you. Also you could refer to the tutorial:Create a function app in Azure.
I´m using az functionapp create for creating function ap in Azure, where apparts of creating the function app it also hooks it to a bitbucket repo. I´m using parametere --deployment-source-url -u but it seems is not working this way and is giving me an error. This is done by a jenkin file pipeline
node {
stage('Azure Login') {
withCredentials([azureServicePrincipal('6-8afd-ae40e9cf1e74')]) {
sh 'az login --service-principal -u $AZURE_CLIENT_ID -p $AZURE_CLIENT_SECRET -t $AZURE_TENANT_ID'
sh 'az account set -s $AZURE_SUBSCRIPTION_ID'
}
}
stage('Build Azure FuntionApp') {
sh 'az functionapp create -g $RG_NAME -p $SP_NAME -n grey-$JOB_NAME-$BUILD_NUMBER -s $SA_NAME --deployment-source-url https:// bitbucket.org/xxxx/functions/s***strong text***rc/develop --debug'
}
If I put --deployment-source-url -u https://user#bitbucket.org I get:
ERROR: az functionapp create: error: argument
--deployment-source-url/-u: expected one argument
I tried without the -u just : --deployment-source-url https://#bitbucket.org
and the job gets done, but the link with bitbucket repos is not made. Getting this:
So how is it that this work? how come if I put user it says invalid argument and if I don´t it pases but It can find user. Does anyone ever used this command to create a function app? thanks!
If you want to create azure function via azure-cli, you could change the deployment resource url after --deployment-source-url. You could refer to my command to create a function with a blob trigger, replace the url of yours. It works fine on my side.
Note: The Access level should be public, you could check it in Settings like the screenshot below.
az functionapp create --deployment-source-url https://bitbucket.org/xxx/azure-function --resource-group resourcegroupname --consumption-plan-location westeurope --name joyfun22 --storage-account <storage_name>
Besides, you also can use a github repository to create a function.
For example, to use the command below to create a function with a blob trigger.
az functionapp create --deployment-source-url https://github.com/Joyw1/Azure-Function-Trigger --resource-group myResourceGroup --consumption-plan-location westeurope --name <app_name> --storage-account <storage_name>
Update:
If your Access level is private. You need a access token to access your bitbucket repository. Please follow the steps bellow.
1.Go to the Bitbucket Labs -> Access Management -> OAuth -> Add consumer
More details, refer to this link.
2.Enable authenticated git deployment with Azure CLI
#!/bin/bash
gitrepo=<Replace with your GitHub repo URL e.g. https://github.com/Azure-Samples/functions-quickstart.git>
token=<Replace with a GitHub access token>
# Enable authenticated git deployment
az functionapp deployment source update-token \
--git-token $token
For complete command, refer to this link.