Deploy an Azure Function created from Visual Studio

I created an Azure Function and added some some code to connect to a database and now I want to deploy it to the Azure platform.

Right-click on the Project and select Publish, as seen in Figure 1.

image

Figure 1, how to publish an Azure Function from Visual Studio, develop local

I chose to create a new Azure Function App, as you can see in Figure 2.

image

Figure 2, how to publish an Azure Function from Visual Studio, develop local, how to create Function App from Visual Studio

Then I filled out the details as seen in Figure 3.

image

Figure 3, how to publish an Azure Function from Visual Studio, develop local, how to create Function App from Visual Studio

And then selected the Create button.  This actually failed, see here “An error occurred”.   The Function App was created, but not the Function.  So I attempted to redeploy again by selecting the newly created Function App, see Figure 4 and all worked out fine.

image

Figure 4, how to publish an Azure Function from Visual Studio, develop local, select existing, how to create Function App from Visual Studio

I selected the Azure Function App from Figure 5.

image

Figure 5, how to publish an Azure Function from Visual Studio, develop local, how to create Function App from Visual Studio

And all worked out just fine.  When I viewed the Azure Function App within the portal it looked like that seen in Figure 6.

image

Figure 6, how to publish an Azure Function from Visual Studio, develop local, how to create Function App from Visual Studio

As I mentioned here “How to create an Azure Function in Visual Studio”, “This if fine, since I decided to create from Visual Studio, I will need to develop, test and publish in Visual Studio from this point on.  Do not think that you can go back and forth between developing in the portal and in Visual Studio.  It is either or and you need to decide how you want to develop.  When created from this direction, I see this, Figure 7 in the portal when I navigate to it.”

When I tested originally, I received the exception shown in Figure 7.

image

Figure 7, how to publish an Azure Function from Visual Studio, develop local, how to create Function App from Visual Studio

I resolved it by adding “DatabaseConnectionString” application setting as I discuss here “How to connect to a database from an Azure Function”.  Issue was that I was reading from the local.settings.json file locally and the value didn’t exist when I published.

Once I added that, all was well, see Figure 8.

image

Figure 8, how to publish an Azure Function from Visual Studio, develop local, how to create Function App from Visual Studio