Let’s deploy the Function to Azure and watch it call SharePoint!
This is the second post about Azure Functions V2, with PnPJs and Visual Studio code. I decided to split this post into two. The next post will focus on using the Azure Key Vault with our JavaScript Solution.
This post is about deploying our app, and while we do that we have a look at the local vs productions variables.
Have a look at the first post if you want to install the prerequisites and build the function from scratch:
Part 1: Azure Functions V2 + VS Code + PnPJs === trueYou could also clone it from my Github and follow the instructions (please have a look at the readme):
Link to GitHub RepositoryAs I mentioned earlier there are multiple ways for us to deploy this function. In the last blogpost we utilized the VS Code extension so let’s go with that first.
Deploy to Function App
Let the extension run its magic. After some time you should receive a message that the function has been deployed. Right now we don’t have any production variables, so we will use an awesome feature in the extension for this. We could also change the settings from the UI in the VS Code extension. Really smooth!
It should now work in Azure, awesome!
We have a couple of options, here are two:
Just to demonstrate how to fetch the Application settings from an existing Function App, we will create a Function App from the UI.
The local.settings.json
is only being used locally, our settings are never transferred to Azure.
If you don’t have a function app from the previous steps, create one here.
create
.
create
We are going to use the Azure Functions Core Tools
that we installed in the previous post, to get the application settings of our newly created app.
We don’t need to get these before we deploy, I’m just showing you that you can. There might be some scenarios where you would want the storage settings etc.
func azure functionapp fetch-app-settings <FuncApp>
So we publish our app and use the local.settings.json
to overwrite the App Settings in Azure. We don’t overwrite and remove all the settings, we just add the new settings and overwrite/update if there are any with the same name.
func azure functionapp publish <FuncApp> --publish-local-settings -i --overwrite-settings -y
And let’s try it in the browser:
So deploying an Azure Function from Visual Studio Code is very easy, I like the Functions Extension. And I really like that we could change the Application Settings easily from the extension.
As you saw in the other example, we created a new Function App to receive the settings from Azure. You don’t have to do that, you could fetch settings from any of your Function Apps.
Another really easy way to deploy this function would be to:
func azure functionapp publish <FuncApp> --publish-local-settings -i --overwrite-settings -y
And of course, we could both get the settings, and set from local settings via the Extension in VS Code.
And you would be done!
Anyways the next post will be using the Azure CLI and Azure Key Vault!