Azure Functions Gettting Started

Update: Stopped for while. Now Azure has changed tremendously. I published this post for me to, at least, have a reference later. The content has never finished 🙁

When something happens, executes a logic, outputs result (if there is) somewhere. At the highest abstraction, it is simple like that, Azure Functions. But its simplicity has captured almost all scenarios in real life.

I was about to write some concepts in Azure Functions. However, MS Docs is so good that you can go ahead and read them. I posted the link below to save you some typing; and for my reference next time

Azure Functions Official Documentation from MS

Trigger – Action – Output

When a result is place into a storage, it triggers another action, and another action. The chain keeps going. It stops when a business requirement is met. The power of Azure Function is here. It gives us a flexible tool to build a complex business process. The limit is our design skills. Yeah, I know that there are limitations in term of technical challenge. But with a good design, architectural skill, you can build almost whatever you want to accomplish.

Trigger Action Output
Trigger Action Output

I am a developer. I need to know deeper. And most importantly, I have to answer this question

What can I do with such a powerful tool?

After reading around the internet and courses from Pluralsight, I head over to Azure portal and start my first function. Most of my writing here is not new. Many have written them. The point of my writing is for my learning purpose. I want to document what I learn in my own words.

Let’s build a simple team cooperation process using available tools. Say in my team whenever we do a release:

  1. Prepare code, build
  2. Prepare release notes
  3. Deploy to test environment
  4. Smoke test
  5. Review system logs

There are more but those are the basic.

Core Concepts

As C# a developer, this document is perfect for my reference.

The biggest challenge, as a developer, is to get it done right. The infrastructure has many built-in support. There are variety of input and output bindings. Each binding has a set of convenient conversion support as well as customization at your disposal.

Azure Function in Azure Portal

 

Azure Function from Visual Studio

Environment: Visual Studio 2017 Enterprise, .NET Core 2.0

After creating a new Function project, here what VS gives me

using System.IO;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.WebJobs.Host;
using Newtonsoft.Json;

namespace Aduze.Functions
{
    public static class HttpTriggerFunctions
    {
        [FunctionName("HttpTriggerDemo")]
        public static IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequest req, TraceWriter log)
        {
            log.Info("C# HTTP trigger function processed a request.");

            string name = req.Query["name"];

            string requestBody = new StreamReader(req.Body).ReadToEnd();
            dynamic data = JsonConvert.DeserializeObject(requestBody);
            name = name ?? data?.name;

            return name != null
                ? (ActionResult)new OkObjectResult($"Hello, {name}")
                : new BadRequestObjectResult("Please pass a name on the query string or in the request body");
        }
    }
}

There are notions of AspNetCore, WebJobs. In HttpTrigger function, the function accepts a HttpRequest and returns IActionResult. Whoever codes ASP.NET MVC knows what they are.

Challenge for Architects

How should you architect a system with all the power you have from Azure?

Write a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.