Software System Requirements
- As a developer, I want to create a new HTTP serverless function and test my new function locally, so that it is ready to be deployed to the Azure Cloud.
- As a developer, I want to add dependency injection to my function, so that I can utilize services or 3rd party libraries.
- As a DevOps Engineer, I want to package and deploy my serverless function to the Azure cloud, so that I allow my team to perform integration tests.
Azure Subscription
.Net 6 SDK
Visual Studio Code
Azure Function Core Tools 4x - Azure Functions Core Tools
Azure CLI - Azure Command-line Interface (CLI)
- Create new project. I created a new project in GitHub named Calculator. I cloned my new Calculator project to my local desktop.
- Navigate into the new Calculator project directory .
- Optional: Initialize git flow. From the Calculator directory, I initialized Git Flow using the following command:
git flow init
- Generate new Azure Function App. I used the Azure Function Core CLI to generate the new function app.
func init Kulba.Function.Calculator --dotnet
- Create a new HTTP function type. Navigate into the new directory Kulba.Function.Calculator that was created in the previous step. Here is another example of the Azure Function Core CLI command to generate the HTTP function. The generator uses the name value to create the new class and to name the function. The template value describes the name of the function. And the authlevel describes the execution security scope.
func new --name Sum --template "HTTP trigger" --authlevel "function"
- Add Serilog packages to project.
dotnet add package Microsoft.Azure.Functions.Extensions
dotnet add package Serilog
dotnet add package Serilog.Extensions.Logging
dotnet add package Serilog.Sinks.Console
dotnet add package Serilog.Sinks.File
- Initialize Serilog in the Program.cs
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Serilog;
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureServices(services =>
{
var logger = new LoggerConfiguration()
.WriteTo.Console()
.WriteTo.File("log.txt", rollingInterval: RollingInterval.Day)
.CreateLogger();
services.AddLogging(lb => lb.AddSerilog(logger));
})
.Build();
host.Run();
Offical Microsoft Azure Functions
- Visual Studio 2022 has the Azure Functions project templates already installed.
- To install the additional Azure Function templates. This gives you the developer the awesome power to create new function apps and function types from the DotNet SDK CLI. This is important if you want to use Visual Studio Code.
dotnet new --install Microsoft.Azure.Functions.Worker.ProjectTemplates