Mastering Azure Serverless Computing - Lorenzo Barbieri - E-Book

Mastering Azure Serverless Computing E-Book

Lorenzo Barbieri

0,0
36,59 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Become an expert in implementing Azure Functions to work seamlessly with your serverless applications




Key Features



  • Develop scalable, robust multi-tier apps without worrying about infrastructure needs


  • Deploy and manage cost-effective and highly available serverless apps using Azure Functions


  • Accelerate enterprise-level application development by seamlessly integrating different cloud services with Azure Functions



Book Description



Application development has evolved from traditional monolithic app development to using serverless options and microservices. This book is designed to guide you through using Microsoft's Azure Functions to process data, integrate systems, and build simple APIs and microservices.






You will discover how to apply serverless computing to speed up deployment and reduce downtime. You'll also explore Azure Functions, including its core functionalities and essential tools, along with understanding how to debug and even customize Azure Functions. In addition to this, the book will take you through how you can effectively implement DevOps and automation in your working environment. Toward the concluding chapters, you'll cover some quick tips, troubleshooting techniques, and real-world serverless use cases that will help you make the most of serverless computing.






By the end of this book, you will have gained the skills you need to develop and deliver cost-effective Azure serverless solutions.




What you will learn



  • Create and deploy advanced Azure Functions


  • Learn to extend the runtime of Azure Functions


  • Orchestrate your logic through code or a visual workflow


  • Add caching, security, routing, and filtering to your APIs


  • Use serverless technologies in real-world scenarios


  • Understand how to apply DevOps and automation to your working environment



Who this book is for



This book is designed for cloud administrators, architects, and developers interested in building scalable systems and deploying serverless applications with Azure Functions. Prior knowledge of core Microsoft Azure services and Azure Functions is necessary to understand the topics covered in this book.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB

Seitenzahl: 277

Veröffentlichungsjahr: 2019

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Mastering Azure Serverless Computing

 

 

A practical guide to building and deploying enterprise-grade serverless applications using Azure Functions

 

 

 

 

 

 

 

Lorenzo Barbieri
Massimo Bonanni

 

 

 

 

 

 

 

 

 

 

BIRMINGHAM - MUMBAI

Mastering Azure Serverless Computing

Copyright © 2019 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Commissioning Editor: Vijin BorichaAcquisition Editor:Meeta RajaniContent Development Editor:Ronn KurienSenior Editor: Richard Brookes-BlandTechnical Editor:Komal KarneCopy Editor: Safis EditingProject Coordinator:Vaidehi SawantProofreader: Safis EditingIndexer:Pratik ShirodkarProduction Designer:Nilesh Mohite

First published: November 2019

Production reference: 1211119

Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK.

ISBN 978-1-78995-122-6

www.packt.com

To my wife, Catia, and my son, Gioele, for their support and encouragement. To all my extended family for their love and dedication.
– Lorenzo Barbieri
To my wife, Floriana, for her patience and support (honey, I love you). To all my family, which has always believed in me.
– Massimo Bonanni
 
Packt.com

Subscribe to our online digital library for full access to over 7,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.

Why subscribe?

Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals

Improve your learning with Skill Plans built especially for you

Get a free eBook or video every month

Fully searchable for easy access to vital information

Copy and paste, print, and bookmark content

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.

At www.packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks. 

Contributors

About the authors

Lorenzo Barbieri specializes in cloud-native applications and application modernization on Azure and Office 365, Windows and cross-platform applications, Visual Studio, and DevOps, and likes to talk with people and communities about technology, food, and funny things.

He is a speaker, a trainer, and a public speaking coach. He has helped many students, developers, and other professionals, as well as many of his colleagues, to improve their stage presence with a view to delivering exceptional presentations.

Lorenzo works for Microsoft, in the One Commercial Partner Technical Organization, helping partners, developers, communities, and customers across Western Europe, supporting software development on Microsoft and OSS technologies. 

I would like to thank Massimo for his hard work and support. I would also like to thank all the people from Packt that worked with us on the book, who were always professional and a source of encouragement. Last but not least, I would like to thank my patient wife, Catia, and my son, Gioele, for their love and support.

 

Massimo Bonannispecializes in cloud application development and, in particular, in Azure compute technologies. Over the last 3 years, he has worked with important Italian and European customers to implement distributed applications using Service Fabric and microservices architecture.

Massimo is an Azure technical trainer in Microsoft and his goal is to help customers utilize their Azure skills to achieve more and leverage the power of Azure in their solutions. He is also a technical speaker at national and international conferences, a Microsoft Certified Trainer, a former MVP (for 6 years in Visual Studio and Development Technologies and Windows Development), an Intel Software Innovator, and an Intel Black Belt.

I would like to thank Lorenzo for thinking of me when he began writing this book and assisting me with my first writing experience. I would also like to thank all the people from Packt that worked with us on this book, who were always professional and provided encouragement. Last, but certainly not least, I would like to thank my patient wife, Floriana, for her love and support (honey, I love you).

About the reviewer

Mikhail Veselov is a professional software developer with over 14 years' experience in .NET stack technologies, and this is the second book he has reviewed. His work with cloud-based applications began in 2011, since when he has completed a variety of projects. He holds two degrees—in math and computer science—from Saint Petersburg State University, Russia. He is also a big fan of the bass guitar and origami. You can ask him any questions at [email protected].

I want to thank all my teachers and those individuals who have helped me during my career, especially the Saint Petersburg Computer Science Center. My personal thanks go to my family, who have supported me throughout my life, and to all my friends all over the world.

Packt is searching for authors like you

If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.

Table of Contents

Title Page

Copyright and Credits

Mastering Azure Serverless Computing

Dedication

About Packt

Why subscribe?

Contributors

About the authors

About the reviewer

Packt is searching for authors like you

Preface

Who this book is for

What this book covers

To get the most out of this book

Download the example code files

Download the color images

Conventions used

Get in touch

Reviews

Section 1: Azure Functions 2.0 Fundamentals

Developing and Running Azure Functions

Technical requirements

Introduction to Azure Functions

Azure Functions Core Tools

Developing Azure Functions with Visual Studio

Visual Studio Code

The OpenAPI Specification in Azure Functions

Exposing your Azure Functions on the internet with ngrok

Debugging an Azure Function

Debugging your function locally

Debug your function remotely

Summary

Questions

Further reading

Customizing Your Azure Functions

Technical requirements

Discovering Azure Functions extensions

Creating a custom trigger

Creating a custom binding

Summary

Questions

Further reading

Programming Languages Supported in Azure Functions

Technical requirements

Azure Functions and JavaScript

Azure Functions and Java

Azure Functions and Python

Azure Functions and PowerShell

Language extensibility

Summary

Questions

Further reading

Section 2: Azure Functions 2.0 Deployment and Automation

Deploying and Configuring Your Azure Functions

Technical requirements

Creating the Azure function app

Deploying the Azure function app

Using the deployment slots

Kudu – the Azure Function deployment service

Configuring your Azure Functions

Reading the app settings in your Azure Function 

Summary

Questions

Further reading

Leverage the Power of DevOps with Azure Functions

Technical requirements

Understanding Azure DevOps

Azure Pipelines and Azure Functions

Creating your first build pipeline

The Variables tab

The Triggers tab

The Options tab

The History tab

The Tasks tab

Using YAML definition

Creating the release pipeline

CI/CD at a glance

Summary

Questions

Further reading

Testing and Monitoring

Technical requirements

Testing your Azure Functions

Dependency injection in Azure Functions

Monitoring Azure Functions

Summary

Questions

Further reading

Serverless and Containers

Technical requirements

Linux-based Azure Functions

Creating an Azure Functions project with support to create a custom Docker image

Creating a custom Docker image that contains an Azure Function

Publishing the custom Docker image to Docker Hub

Publishing the custom Docker image to an ACR

Creating a function app based on a custom Docker image

Updating the Docker image

Pointing the function app to a new tag and enabling continuous deployment

Hosting Azure Functions containers in Kubernetes with KEDA

Installing KEDA in the Kubernetes cluster

Deploying and executing your functions in Kubernetes

Azure Container Instances

Summary

Questions

Further reading

Section 3: Serverless Orchestration, API Management, and Event Processing

Orchestration as Code - Durable Functions

Technical requirements

What are Durable Functions?

Function types

Client functions

Orchestrator functions

Activity functions

The Durable Functions execution state

Managing Durable Functions versioning

Order manager sample

OrderReceiver

OrderConfirmed

OrderCancelled

OrderCancelled time expired

Summary

Questions

Further reading

Orchestration as Design - Logic Apps

Technical requirements

Understanding Logic Apps

Logic App service components

Versioning, monitoring, and API connections

Versioning

API connections

Monitoring

Advantages of using Logic Apps

Summary

Questions

Further reading

Empowering Your Serverless API with API Management

Technical requirements

Understanding Azure API Management

Creating an API Management instance

The developer portal

Exposing a new API

Creating a new policy

Defining a new product

The API Management REST API 

Advantages of API Management

Summary

Questions

Further reading

High-Scale Serverless Event Processing with Event Grid

Technical requirements

Understanding Event Grid

Events

Event sources

Topics

Event subscriptions

Event handlers

Creating an Event Grid subscription

Understanding event delivery and retries

Summary

Questions

Further reading

Section 4: Real-World Serverless Use Cases

Best Practices and Use Cases for Azure Serverless Computing

Azure serverless best practices

Choosing between consumption plans and traditional ones

Serverless scenarios

Traditional PaaS scenarios

Azure Functions – differences between consumption plans and app service plans

Azure Functions – premium plan

API Management – difference between consumption plans and traditional plans

Azure Functions best practices for scalability and performance

Some Azure serverless use cases

IoT and Edge devices

Backend for single-page web apps or mobile apps

Integrate different SaaS services

Backend for Amazon Alexa skills

Summary

Questions

Further reading

Assessments

Chapter 1, Developing and Running Azure Functions

Chapter 2, Customizing Your Azure Functions

Chapter 3, Programming Languages Supported in Azure Functions

Chapter 4, Deploying and Configuring Your Azure Functions

Chapter 5, Leverage the Power of DevOps with Azure Functions

Chapter 6, Testing and Monitoring

Chapter 7, Serverless and Containers

Chapter 8, Orchestration as Code – Durable Functions

Chapter 9, Orchestration as Design – Logic App

Chapter 10, Empower Your Serverless API with API Management

Chapter 11, High Scale Serverless Event Processing with Event Grid

Chapter 12, Best Practices and Use Cases for Azure Serverless Computing

Another Book You May Enjoy

Leave a review - let other readers know what you think

Preface

Application development has evolved from traditional monolithic app development to using serverless options and microservices. Building highly scalable applications using a serverless approach and Azure technologies is a challenge for most organizations. Mastering Azure Serverless Computing covers all Azure serverless technologies, as well as both the technical and business aspects of using serverless inside Azure, showing how and when to use every technology in an effective way.

Who this book is for

This book is intended for people who already know serverless technologies but who require a more detailed understanding.

This book begins with a look at various tools that you can use to develop, test, and deploy solutions based on Azure Functions. You will learn how you can extend the Azure Functions runtime to support your custom triggers and bindings. You will also learn what programming languages Azure Functions supports, and how you can use the language extensibility to create support for your favorite language. With a strong foundation in Azure Functions 2.0, you will learn how to deploy and configure an Azure function and understand how you can test (using the dependency injection pattern inside your Azure Functions) and monitor a complete solution. You will also see how API Management and Event Grid can be used in a serverless manner. Toward the end of the book, you will get to grips with technical and cost-related best practices. The book will also show you how to use, and when to avoid, serverless in solutions that are under our control or that should incorporate parts from different sources.

By the end of the book, you will be working seamlessly with Azure Functions.

What this book covers

Chapter 1, Developing and Running Azure Functions, shows you what kinds of tools can be used to develop, test, and deploy a solution based on Azure Functions. 

Chapter 2, Customizing Your Azure Functions, explains how you can implement your custom triggers and bindings to adapt Azure Functions to your requirements.

Chapter 3, Programming Languages Supported in Azure Functions, covers what programming languages are supported by the Azure Function runtime and how you can support your favorite programming language.

Chapter 4, Deploying and Configuring Your Azure Functions, explains how to deploy your Azure Functions on Azure and how you can configure them.

Chapter 5, Leverage the Power of DevOps with Azure Functions, explains how you can leverage the power of Azure DevOps on your Azure Functions, and how to implement a CI/CD approach in serverless technologies.

Chapter 6, Testing and Monitoring, shows how you can test your Azure Functions using dependency injection and how you can monitor them in a production environment.

Chapter 7, Serverless and Containers, explains how you can leverage the power of containerization to host Azure Functions to have high scalability on your solutions.

Chapter 8, Orchestration as a Code – Durable Functions, explains what Durable Functions is and how you can use it to implement a workflow using a programming language.

Chapter 9, Orchestration as Design – Logic Apps, covers what Logic Apps is and how you can use it to implement a workflow using a design approach.

Chapter 10, Empowering Your Serverless API with API Management, explains what API Management is and why it is important in a serverless world.

Chapter 11, High-Scale Serverless Event Processing with Event Grid, explains what Event Grid is and why it is important to implement an event-driven architecture.

Chapter 12, Best Practices and Use Cases for Azure Serverless Computing, differs from the other chapters in that it builds upon the technologies that you have learned and explores some best practices and use cases for Azure serverless computing.

To get the most out of this book

In this book, we assume that the reader already knows the fundamentals of serverless and serverless technologies in Azure and that they also have knowledge of C#.

Download the example code files

You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packtpub.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

Log in or register at

www.packt.com

.

Select the

Support

tab.

Click on

Code Downloads

.

Enter the name of the book in the

Search

box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

WinRAR/7-Zip for Windows

Zipeg/iZip/UnRarX for Mac

7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Mastering-Azure-Serverless-Computing. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://static.packt-cdn.com/downloads/9781789951226_ColorImages.pdf.

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "An Azure Function written in C# is a static method decorate by a FunctionName attribute."

A block of code is set as follows:

public static class SimpleExample{ [FunctionName("QueueTrigger")] public static void Run( [QueueTrigger("inputQueue")] string inItem, [Queue("outputQueue")] out string outItem, ILogger log) { log.LogInformation($"C# function processed: {inItem}"); }}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

public static class SimpleExample{

[FunctionName("QueueTrigger")]

public static void Run( [QueueTrigger("inputQueue")] string inItem, [Queue("outputQueue")] out string outItem, ILogger log) { log.LogInformation($"C# function processed: {inItem}"); }}

Any command-line input or output is written as follows:

c:>npm install -g azure-functions-core-tools

Bold: Indicates a new term, an important word, or words that you see on screen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Simply choose the menu File | New | Project."

Warnings or important notes appear like this.
Tips and tricks appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in, and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packt.com.

Section 1: Azure Functions 2.0 Fundamentals

This section shows the reader how to create an Azure Function, how it works, how to customize it, and how to use languages other than C#.

It comprises the following chapters:

Chapter 1

,

Developing and Running Azure Functions

Chapter 2

,

Customizing Your Azure Functions

Chapter 3

,

Programming Languages Supported in Azure Functions

Developing and Running Azure Functions

Azure Functions is one of the serverless technologies offered by Azure. It allows you to run code on-demand in response to a variety of events.

In this chapter, we will provide a brief explanation of what Azure Functions is and how it works. We will also introduce all the tools you can use to create, develop, and test a solution based on Azure Functions. The first tool we will look at is Azure Functions Core Tools, which is the most important tool you can use when you start to develop your Azure Functions solution because with it you can create, test, and deploy your Azure Functions. In this chapter, you will also learn how Visual Studio and Visual Studio Code can help you to improve your developer experience and how you can use other tools to support the documentation and testing phases.

This chapter will cover the following topics:

Introduction to Azure Functions

Azure Functions Core Tools and the Azure Functions runtime

Creating Azure Functions in Visual Studio and Visual Studio Code

Using the OpenAPI specification to document the API

Using ngrok to expose a local Azure Function

on

the internet

Deb

ugging an Azure Function both locally and remotely

Technical requirements

If you want to start to develop solutions with Azure Functions, you have to know one of the languages Azure Functions supports (at this moment in time, C#, JavaScript, Java, and Python). If you do, you'll easily be able to follow this book.

The Microsoft entry point for the Azure Functions documentation is located at https://azure.microsoft.com/en-us/services/functions/. Starting from there, you can find technical documentation, whitepapers, and samples, and you can navigate to the GitHub repositories for the different tools you'll encounter in this book.

Finally, you can find the source code for this book at https://github.com/PacktPublishing/Mastering-Azure-Serverless-Computing/tree/master/Chapter01.

Introduction to Azure Functions

The Azure Functions platform allows you to run a piece of code (basically a simple function) in response to a wide variety of events; for example, you can run code when a client makes an HTTP request or when someone puts a message into a queue.

There are two fundamental concepts to understand when approaching the world of Azure Functions—triggers and bindings:

Triggers are what cause a function to run; they define what kind of event the function responds to. A trigger tells you how a function is called, and a function must have exactly one trigger. Triggers have associated data, which is often provided as the payload of the function, and you can use the data contained in the payload to better understand the nature of the event that wakes up your function.

Bindings are the way functions can exchange data with other cloud services such as Storage, Queue, or Cosmos DB. Bindings are defined in a declarative way: this means that you declare what kind of binding you need (for example, you might want to manage data with a Cosmos DB instance or write data into Azure Table storage) and the Azure Functions runtime provides the actual instance

to the function

to manage the data.

An Azure Function can have multiple bindings, and every binding can manage data input or output (or both—binding data can be received by the function or sent by the function to the connected services). A trigger can have only the input data (a trigger only receives data from the connected services and cannot send data to the services).

In version 1.x of the Azure Functions runtime, triggers and bindings were included in the runtime itself, while in version 2.x, triggers and bindings must be added as extensions, using NuGet packages. This means that you can reference only triggers and bindings you actually need and don't need to have all the supported triggers and bindings available for Azure Functions. Furthermore, the extension approach used by version 2.x allows you to create your own triggers and bindings. The advantage of being able to implement your own triggers and bindings is to delegate to the runtime the creation and the life cycle of the instances used by the function. In essence, the runtime acts as a dependency resolver for the instances required for the function. In runtime version 2.x, the only triggers available without adding extensions as NuGet packages are HttpTrigger and TimeTrigger; they are included in the Azure Functions SDK.

At the time of writing this book, the languages supported by Azure Functions (in version 2.x) are C#, F#, JavaScript, Java, Python (in preview), and PowerShell. The following table shows all the languages supported by the related frameworks:

Language

Framework

C#

.NET Core 2.x

JavaScript

Node.js 8 and 10

F#

.NET Core 2.x/3.x

Java

Java 8

Python

Python 3.6

TypeScript

Supported through transpiling to JavaScript

PowerShell

PowerShell Core 6 (preview)

 

The Azure Functions runtime is also designed to support language extensibility; that is, it's possible to create your own language worker process to manage your own programming language. The JavaScript and Java languages are built with this extensibility.

As for version 1.x of Azure Functions, a function app is a container of your functions. In version 2.x of the Azure Functions runtime, unlike what happened in version 1.x, a function app can host functions written in a single programming language.

An Azure Function written in C# is a static method decored by the FunctionName attribute:

public static class SimpleExample{ [FunctionName("QueueTrigger")] public static void Run( [QueueTrigger("inputQueue")] string inItem, [Queue("outputQueue")] out string outItem, ILogger log) { log.LogInformation($"C# function processed: {inItem}"); }}

FunctionName allows you to set the name of the function that is the function entry point. The function name must be unique in your project (that is, the function name must be unique in a function app). It starts with a letter and only contains letters, numbers, _, and -, and is up to 127 characters in length. You can call the method what you like—the Azure Functions runtime doesn't care about the name of the method but only the name of the function defined in the FunctionName attribute. The project template often creates a method called Run but you can change it.

The method signature can contain more parameters other than the one that defines the trigger. You can have the following:

Input and output bindings marked as such by decorating them with attributes. In the previous sample, the

Queue

attribute

declares that the string (the actual type bound by the runtime) will be saved (because it is an

out

parameter) in a storage queue called

outputQueue

when the method ends.

An

ILogger

or

TraceWriter

(TraceWriter is available only for version 1.x) parameter for logging.

A

CancellationToken

parameter for graceful shutdown in an async function.

Binding expression parameters to get trigger metadata.

The arguments of the attribute support binding expressions that provide the possibility to use values defined in the app settings or retrieve special information from the binding.

For example, consider this sample:

public static class BindingExpressionsExample{ [FunctionName("LogQueueMessage")] public static void Run( [QueueTrigger("%queueappsetting%")] string myQueueItem, DateTimeOffset insertionTime, ILogger log) { log.LogInformation($"Message content: {myQueueItem}"); log.LogInformation($"Created at: {insertionTime}"); }}

The name of the trigger queue is defined in the app settings using the queueappsetting key, as shown in the next snippet:

{ "IsEncrypted": false, "Values": { "AzureWebJobsStorage": "UseDevelopmentStorage=true", "FUNCTIONS_WORKER_RUNTIME": "dotnet", "queueappsetting" : "inputqueue" }}

While the value contained in the insertionTime parameter is retrieved from the message creation time in the storage queue.

You can find all the possible triggers, binding parameters, and binding expressions in the official documentation. For Queue (based on storage account), the official documentation is located at https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-queue.

Once you write your function, you can build it (you'll learn how later in the chapter) and the build process will generate a folder structure like the following diagram:

As you can see, the build tool creates, as usual, the bin folder where you can find all the mandatory assembly for your code. Then, it also creates two essential files:

function.json

: In this file, you can find the metadata of the single function in terms of triggers, bindings, and assembly. For example, if you build a project that contains the previous

LogQueueMessage

function, the

function.json

file will look like this:

{ "generatedBy": "Microsoft.NET.Sdk.Functions-1.0.24", "configurationSource": "attributes", "bindings": [ { "type": "queueTrigger", "queueName": "%queueappsetting%", "name": "myQueueItem" } ], "disabled": false, "scriptFile": "../bin/MyFunction.dll", "entryPoint": "MyFunction.BindingExpressionsExample.Run"}

The configurationSource property tells the runtime that the code uses the attribute approach for trigger and bindings while the bindings section contains the complete definition for each binding involved in the function.

You can find other examples of function.json in the Azure Functions GitHub repository (https://github.com/Azure/azure-functions-host/wiki/function.json), while the JSON schema is available at http://json.schemastore.org/function.

host.json

: This file contains the global configuration for the entire function app. For example, you can find the runtime version to use for hosting functions here. If you are using .NET Core 2.x, you can also put your configuration data in

appsettings.json

or

local.settings.json

(only for local test and debugging).

You can find more information about thehost.json schema and configurations at https://docs.microsoft.com/en-us/azure/azure-functions/functions-host-json, while more information about appsetting.json is available at https://docs.microsoft.com/en-us/azure/azure-functions/functions-app-settings.

The entire Azure Functions ecosystem is open source, and a set of GitHub repositories contains all the different components related to the Azure Functions world. Here is the list of GitHub repositories currently available:

Azure Functions:

https://github.com/Azure/Azure-Functions

Azure Functions host:

https://github.com/Azure/azure-functions-host

Azure Functions portal:

https://github.com/azure/azure-functions-ux

Azure Functions templates:

https://github.com/azure/azure-functions-templates

Azure Functions Core Tools

The Azure Functions runtime (runtime for short) is part of Azure Functions Core Tools, a set of Command-Line Interface (CLI) tools that allow you to run, test, and deploy your functions and that you can install on your PC or server.

There are two versions of Azure Function Core Tools:

Version 1.x

: This version can run only on Windows and supports version 1.x of the Azure Functions runtime. It supports .NET Framework 4.7.1 only.

Version 2.x

: This version can run on Windows, macOS, and Linux and supports the 2.x version of the Azure Functions runtime.

The 2.x version of the tool contains the 2.x version of the Azure Functions runtime. It is based on .NET Core and can run on all platforms that support .NET Core 2.x and 3.x (Windows, macOS, and Linux).

Azure Functions Core Tools (both v1.x and v2.x) is open source under the MIT License, and you can find it on GitHub at https://github.com/Azure/azure-functions-core-tools.

The first step to use the tool is, therefore, to install .NET Core on your machine. You can install the tool in different ways depending on whether you are on Windows, macOS, or Linux.

If you are on Windows, you can use Chocolatey or npm.

Chocolatey and npm are two package managers for Windows: using them, you can install tools and applications using CLI (you don't need to care about finding the right installation package, download it and install):

For example, to install the latest version of Azure Functions Core Tools using Chocolatey, you can open Command Prompt and write the following command:

C:>choco install azure-functions-core-tools

If you prefer npm, you can open Command Prompt and write this command:

C:>npm install -g azure-functions-core-tools

If you are on macOS, you have to use Homebrew:

brew tap azure/functions

brew install azure-functions-core-tools

Finally, if you are on Linux (Ubuntu or Debian), you have to use APT, and in particular, you have to register the Microsoft product key as a trusted key:

curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg

sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg

Then, you can add the

APT

source and install the package:

sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-$(lsb_release -cs)-prod $(lsb_release -cs) main" > /etc/apt/sources.list.d/dotnetdev.list'

sudo apt-get update

sudo apt-get install azure-functions-core-tools

Of course, you can also use a more productive tool, such as Visual Studio or Visual Studio Code, but it's important to understand that you can perform all the basic operations using Azure Functions Core Tools and that all your functions run inside the Azure Functions runtime.

Once you install the tools, you can start your journey into the Azure Functions development world.

You can show the help for Azure Function Core Tools by merely running the func command (without any parameters):

C:\MasteringServerless>func

The following screenshot shows the output of the preceding command:

As you can see, Azure Function Core Tools has the concept of context; the context is the scope in which you want to work, for example, function is the context to manage Azure Functions, while durable is the context to work on Azure Durable Functions.