How do I get into the folder of a Web App in Azure - azure

Recently I am trying to use:
func azure functionapp publish WebAppName --publish-local-settings -i
to publish local.settings.json to a web app (actually an Azure function) but I get this error message:
Unable to find project root. Expecting to find one of host.json in project root.
I have logged in to Azure with az login but it looks like I need to get into the folder where I have deployed the Azure function where all those json files are.
A little background, we are using Octopus Deploy to deploy to an Azure function. After the deployment, we want to add a step so that the local.setting.json will be used to populate app settings.
So how do we change the current folder to be in the Azure function root where all those json files are?
Thanks a lot in advance!

You need to go to your local function project folder to run the command, for example, my function project is under MyFunctionProj folder.
Execute the command
func azure functionapp publish tonyfunc --publish-local-settings -i --publish-settings-only
By the way, if you just want to update the settings, you need add --publish-settings-only parameter.
Reference:
Core Tools development

Related

Can't find app with name error while publish the azure function

I tried to create an azure function using following link in Ubuntu system(16.04).
[azure function][2]
Deployment using arm template and create a local azure function using vs code.
Folder contains following files
LocalFunctionProj.csproj, HttpExample.cs, host.json, local.settings.json
azure function is created successfully in portal after deployment.But when i tried to publish the local azure function ,it shows an error Can't find app with name "HttpExample" while using following command
func azure functionapp publish HttpExample
Is anything wrong in my step.
Also i tried this command after 30 mnt when function created in portal
screen shot
I had a similar issue when I followed a tutorial about Azure Functions Core Tools from Microsoft Learning.
In my case, I had the error Can't find app with name X, because I had a wrong subscription set in my local Azure CLI. The command from below changes subscription for the one that is created with "Microsoft Learning Sandbox". Note that, in your case, the name of the subscription can be different.
az account set --subscription "Concierge Subscription"
If it's not the issue, your question suggests that your function app name should be HttpExample. You need to ensure beforehand that there's a function app with such a name in the subscription you are logged into with Azure CLI.
Moreover, there is a ProvisioningState: Failed in the screenshot, which could also be an issue.
If you want to publish the local app into azure ,you must create the functional app before in azure portal.Also the name of the azure function is portal should be same as the local azure app.otherwise you can't publish the app.

public Azure Function that can overwrite and save files in wwwroot of other azure applications? in particular aspx and run.csx files

possible to have a public Azure Function that can overwrite and save code files in wwwroot of other azure applications? in particular aspx and run.csx files?
I understand the security risks, but the idea to have the Azure Function do this with a hard coded specific service account with rights and for two very specific aspx and run.csx files.
Neither of these requires a compile step in the Azure portal UI and wonder about that as well.
Just a question, not looking for best practices or reasons why we should not do this.
If you dont need to compile, just save the code and files,that is no problem.
But it can only be saved, it will not be a real web app, just some files.
You can use zip deploy or FTP to deploy the azure function app to azure and include the files you want to save.
If you Use zip deploy, just zip the files and code with the function app. And then use this command to deploy them to azure:
Azure CLI:
az functionapp deployment source config-zip -g <resource_group> -n <app_name> --src <zip_file_path>
PowerShell:
Publish-AzWebapp -ResourceGroupName <group-name> -Name <app-name> -ArchivePath <zip-file-path>
This is offcial doc:
https://learn.microsoft.com/en-us/azure/azure-functions/deployment-zip-push
Or you can use FTP to upload files.
Go to this place to get the host name:
Go to this place to get the username and password:
And then use them to connect to your function physical path:
At last you can upload anything to the wwwroot of your function app on azure.
This is the offcial doc:
https://learn.microsoft.com/en-us/azure/app-service/deploy-ftp
If you just want to rewrite the file under wwwroot folder, yes this is possible.
I have two function in the portal, in the HttpTrigger1 function I rewrite the HttpTrigger2 content. Below is HttpTrigger2 original content.
Below is HttpTrigger1 code, write a string to HttpTrigger2 run.csx.
Here is the result, after running HttpTrigger1, the HttpTrigger2 content is changed.

Azure Functions App is Read Only after publishing

I have several Azure Functions Apps (c#, javascript and python) and after some time they were all randomly set to Read Only mode. The strange thing is that only one of these 3 function apps were updated before this happened. I know that this is not necessarily a problem, but I want to be able to make edits from the portal.
I can't open App Service Editor
I can't set the app to Read/Write from Function App Settings -> Function app edit mode
I also tried using "func azure functionapp publish myAzFuncAppName --nozip", but with the same result
Of course. Please notice that if the function is 'deployed' to Azure, what will be deployed is the compiled file.
For example, if you deploy C# function app, what will be deployed is the dll file. So this is why it is readonly.
Changes to the code should be done before compiling them into corresponding 'cannot be edited' files, which requires special attention.
But for the modification of the declarative part and the configuration part of the function, this is possible, the specific steps are as follows:
Declarative part:
Then click Debug Console > cmd:
Go to site\wwwroot[yourfunctionname], and there will be a function.json.
Click the 'pen' to edit and don't forget to save.
Configuration part:
You can change the settings from Azure Portal or by editing the application settings. FUNCTION_APP_EDIT_MODE allows values readwrite and readonly, a
Just deleted the Azure Function App, created a new one, transferred the code in the new one and deployed -> still read only, but now I was able to open "App Service Editor" and remove "generated by..." from function.json and then set "Read/Write" from Function App Settings -> Function app edit mode.
Still... I can't see/edit the code of the function, only of function.json and if I redeploy using Azure extensions of Visual Code or powershell with --nozip attribute, the "generated bla bla" appears again :(
When the application runs from package, the files are loaded from that package. Hence those files are not editable.
You need to set WEBSITE_RUN_FROM_PACKAGE : 0 in app settings and redeploy the application again to make the function app editable.
refer https://social.msdn.microsoft.com/Forums/en-US/972d843c-8bdc-4cfc-9c6d-263df196d37c/azure-function-app-readonly-mode?forum=AzureFunctions
UPDATED:
You can deploy functionapp through command line from visual studio code. Try below command.
func azure functionapp publish --nozip
The nozip flag would set Run-From-Package mode off .
you can access other information regarding that command with func azure functionapp publish --help

In Azure Functions, where do we put settings we want to put on Azure?

So just started playing with Azure Functions, I have a new project with some appsettings in the local.settings.json file.
So this works on my local, but obviously when I deploy to Azure Functions, local.settings.json file isn't used.
Where are we supposed to specify our settings for an Azure Function?
Is there a azure.settings.json file? Or some sort of way to deploy an settings file during the deployment?
If you want to add settings, you could use the way provided by Matt, and if you want to deploy the Function to Azure with the settings in the local.settings.json, there is another way to implement it.
Install the Azure Functions Core Tools on the local, publish the Function with -publish-local-settings -i and if you are using the version 2 the --publish-settings-only -o could only publish settings and skip the content.
The below pic is a sample, you could find it will prompt to overwrite value in azure if setting is different between azure and local.settings.json.
Further more information, you could refer to this tutorial: Publish to Azure.
Just like an Azure App Service, and Azure Function has an Application Settings tab where you can configure these through the Azure Portal. To access these you go to: Your function app > Overview > Configured Features> Configuration, you can then add the settings that you need under the Application Settings tab.
Alternatively, if you would prefer configuring these through a CLI then that option is also available. The main documentation is here.
Edit
For a solution as part of your CI/CD you have two options (examples will use Azure DevOps and perform the action in the CD step):
PowerShell Task. You could add a Powershell (or any type of script that will talk to the Azure CLI for functions) script as part of your CD step. This post goes through the process step by step, the bit you are probably interested in is under "Deploying with Azure DevOps Release Pipeline". Essentially it is building up a collection of your appsetting keys and their values, then a call to Set-AzureRmWebApp the and pass in the collection to the -AppSettings flag as per these docs
Azure CLI task. Same as above but you could use the Azure CLI task along with the Inline script option to call the az functionapp config appsettings set command docs here. The --settings flag takes:
Space-separated app settings in a format of =.
So
az functionapp config appsettings set --name MyFunctionApp --resource-group MyResourceGroup --settings "settings1Key=settings1Value settings2Key=settings2value"
The Azure Functions for .NET template for CI (Build) and Deploy a function app to Azure Functions template for CD (Release) inside Azure DevOps will come in handy.

Azure Function how to move appsettings from local to server and vice versa

I m a little new to Azure.
Issue is I m developing Azure Functions and some times I have to work locally (code/ test etc) and other times on Azure. Every time I switch I have to compare and change app settings manually.
Is there a way I can avoid it ? Something where if I run locally I may get latest from server without manual and when I go to server Azure may be aware of my changes ?
Thanks
Yes, use the Azure Functions Core Tools —
Usage: func azure functionapp <action> [-/--options]
fetch-app-settings Retrieve App Settings from your Azure-hosted
Function App and store locally Aliases:
fetch-app-settings, fetch
and
Usage: func azure functionapp <action> [-/--options]
publish Publish the current directory contents to an
Azure Function App. Locally deleted files
are not removed from destination.
<FunctionAppName> Function App name
--publish-local-settings [-i] Updates App Settings for the
function app in Azure during deployment.
--publish-settings-only [-o] Only publish settings and skip the
content. Default is prompt.
--overwrite-settings [-y] Only to be used in conjunction with -i or -o.
Overwrites AppSettings in Azure with local
value if different. Default is prompt.
There's also encryption for the local file if you feel a little adventurous —
run func settings to get usage.

Resources