Book Image

Learning Azure Functions

Book Image

Learning Azure Functions

Overview of this book

Functions help you easily run small pieces of code in cloud with Azure functions without worrying about a whole application or the infrastructure to run it. With Azure functions, you can use triggers to execute your code and bindings to simplify the input and output of your code. This book will start with the basics of Azure Functions. You will learn the steps to set up the environment and the tools that we will be using in the further chapters. Once you have a better understanding of this, we will be creating our first hello world function app. Later you will be introduced to triggers, how they are used to activate a function, and how binding can be used to output results of a function.You will also explore the steps to create an assembly with complex functionality that can be used by functions. Next, this book will teach you to scale your functions and use them to process data, integrate systems, and build simple APIs and microservices. Finally, this book will cover some diagnostic techniques with Azure App services and best practices of working with Azure Functions. By the end of this book, you will be well-versed with the techniques of scaling your Azure functions and making the most of serverless architecture.
Table of Contents (17 chapters)
Title Page
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Customer Feedback
Dedication
Preface

Preface

Serverless is not actually serverless. It means that users only need to manage code/applications and not servers. The server will be managed by the service provider. We as users only pay when our code or function is executed in the serverless or in a server that is not managed by us. Scaling is based on request and pricing differs based on the service provider.

AWS Lambda and Azure Functions are two examples of serverless computing or Function as a Service. Azure Functions enable us to create serveless applications in the Microsoft Azure environment. Azure Functions are open sourced and available on GitHub. They support different languages such as C#, F#, Node.js, Python, PHP, batch, bash, or PowerShell.

It is always best to focus on building innovative applications that help businesses to grow in different dimensions. So, it is important to de-focus from provisioning, managing and maintaining servers, managing high availability, and configuring security. Azure Functions allow us to focus on building applications with a serverless architecture.

Additionally, if we can utilize DevOps practices such as Continuous Integration, Continuous Monitoring, and Continuous Delivery with approval mechanisms using Visual Studio Team Services, that is the a cherry on the cake, isn't It?

What this book covers

Chapter1, Introducing Microsoft Azure Services and Functions, describes in detail the fundamental concepts and terminology to give the reader a baseline understanding of cloud computing, cloud service models, cloud deployment models, functions and some of the related concepts in Microsoft Azure.

Chapter 2, First Function App – Anatomy and Structure of a Function App, covers how to focus into creating our first Azure Function. We will create the Azure Function App and then we will create the Azure Function with trigger and output binding.

Chapter3, Application of Triggers, provides insights on how we can create triggers. Triggers are nothing but a set of functions that get executed when some event gets fired. There are different types of triggers, such as implicit triggers, and we can also create manual triggers. In this chapter, we will cover an overview of triggers and different types of triggers such as HTTP, Event Bus, Service Bus, and Storage.

Chapter4, Bindings, describes bindings in detail. In Azure Function, a binding is used to bind other Azure resources to our Azure Function. We will cover different input/output bindings in this chapter. Brief details will be given about Input bindings such as Blob storage, Storage tables, SQL tables, and NoSQL DBs. Details about output bindings such as HTTP (REST or Webhook), Blob Storage, Events, Queues and topics, Storage tables, SQL tables, NoSQL DBs, Push Notifications, and SendGrid email will also be provided. We will create an example of binding an Azure Function to the event hub, service bus and binding of Azure function with Service bus queue, and also storage.

Chapter5, Webhooks for Azure Functions, covers how to create JavaScript functions triggered by Webhook, how to use Webhook with Azure Functions, and how to use an event with an Azure Function.

Chapter6, The Real World – Functions to Build Consumable APIs, provides insights into how to use the previously-discussed concept of triggers. Bindings work together to bring some real-world functionality to life. First, we will give an outline of the project that we will try to implement; then, we will try to build or architect a solution. We will build the project, use storage, and then verify the whole exercise.

Chapter 7, Managing and Deploying Your Code, talks about DevOps practices such as Continuous Integration and Continuous Delivery using Microsoft Azure Functions and Visual Studio Team Services. DevOps is a combination of Development and Operations. DevOps is not a tool, a technology, or a framework. DevOps is a culture. It is a culture that brings improvement in the outcome and productivity of the resources. We will create a project in VSTS and then configure Continuous Integration and Continuous Delivery for Azure Functions.

Chapter8, Business Considerations, covers details about how to monitor the health of Functions. Azure Functions have their own kind of monitoring, which is useful but basic. For an advanced level of monitoring, we will utilize Application Insights. Another important business consideration is to understand pricing concepts so that we can make an informed decision based on anticipated load, growth, and product roadmap. This chapter will also cover the integration of Application Insights and Azure Functions, pricing/hosting plans, and best practices.

Chapter9, Working with Different Languages, shows you how to use Azure Functions with other languages such as C#, Python, F#, PHP, and JavaScript. This chapter focuses on the Python Function App and PHP Function App.

What you need for this book

This book is for beginners. This book assumes that you are familiar with at least JavaScript, Python, PHP, and other programming languages. Knowledge of these programming languages is essential considering this book to gain better insight. Having a strong understanding of program logic will provide you with the background to be productive with Azure Functions while creating serverless architecture.

As we are going to use Microsoft Azure Functions, you need to have an Azure subscription or free trail to utilize Azure Functions. For basic functions, Azure Functions can be used freely without using a Microsoft Azure Account.

In this book, we cover Continuous Integration and Continuous Delivery for Azure Functions, so it is essential to have a Visual Team Studio Services (VSTS) account and some basic knowledge of it. You can utilize the Implementing DevOps with Microsoft Azure book available at https://www.amazon.com/Implementing-DevOps-Microsoft-Azure-Mitesh-ebook/dp/B01MSQWO4W for DevOps, Microsoft Azure, and VSTS-related basic knowledge. It is good to have some knowledge of repositories such as svn and Git as in Continuous Integration and Continuous Delivery. For Azure Functions, we are going to use a VSTS repository to store the code for the functions.

Additionally, you will need access to the internet to access Azure Portal. Any normal hardware configuration is good enough, such as 4 GB RAM and 500 GB hard disk, to access Microsoft Azure Portal and work with different functions.

Who this book is for

Learning Azure Functions is for beginners. This book targets developers and system administrators who are involved in application development and are looking to automate it. Developers, technical leads, and architects too are the target readers to jumpstart Azure Functions. The reasons to jumpstart Azure Functions are to understand importance and effective usage of Serverless Architecture in application building.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "We can include other contexts through the use of the include directive."

A block of code is set as follows:

{
"bindings": [
{
"name": "myBlob",
"type": "blobTrigger",
"direction": "in",
"path": "photographs/{name}",
"connection": "origphotography2017_STORAGE",
"dataType": "binary"
},

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

"name": "myBlob",
"type": "blobTrigger",
"direction": "in",
"path": "photographs/{name}",
"connection": "origphotography2017_STORAGE",
"dataType": "binary"
},

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

# cp /usr/src/asterisk-addons/configs/cdr_mysql.conf.sample     /etc/asterisk/cdr_mysql.conf

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "clicking the Next button moves you to the next screen."

Note

Warnings or important notes appear in a box like this.

Note

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to [email protected], and mention the book title via the subject of your message.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

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

You can download the code files by following these steps:

  1. Log in or register to our website using your email address and password.
  2. Hover the mouse pointer on the SUPPORT tab at the top.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box.

 

  1. Select the book for which you're looking to download the code files.
  2. Choose from the drop-down menu where you purchased this book from.
  3. Click on Code Download.

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/Learning-Azure-Functions. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/LearningAzureFunctions_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at [email protected] with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.