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

An overview of Microsoft Azure Services


Microsoft Azure falls into the category of a public cloud deployment model when we consider the definition of cloud computing by the National Institute of Standards and Technology (NIST). Let's first understand the different services of Microsoft Azure and some of the terminology that will be useful later in the book.

Microsoft Azure provides different kinds of services based on different use cases. Let's understand the core concepts to make our foundation robust.

Microsoft Azure comes up with some core concepts that are important to understand before we go ahead and work with it. These core concepts helps us to manage resources and understand the pricing structure as well.

Regions

Microsoft Azure services are available in 34 regions around the globe and they are continuously planning to support more regions. The more regions, the greater the number of customers allowed to achieve better performance with cost optimization. It also helps in the scenarios where data location is legally restricted.

Note

To get the latest details on Microsoft Azure regions, visit https://azure.microsoft.com/en-in/regions/.

To verify Azure Functions available by region, go to https://azure.microsoft.com/en-in/regions/services/ and check the Functions section:

Azure is generally available in 34 regions and 12 Graphic Environment Operating Systems (GEOSs) around the globe. It has already announced plans for 6 additional regions and 2 additional GEOSs. For customers, it is extremely important to have legal compliance in the context of storage location of their data. There are two different possibilities/authorities in this scenario:

  1. Customers may copy, move, or access data from any location
  1. Microsoft may replicate data in other regions of the same GEO for high availability:

Note

To get more details, go to http://azuredatacentermap.azurewebsites.net/.

Resource groups

Resource groups in Microsoft Azure are logical containers. A resource group is useful for managing resources and providing role-based access to all the resources available in the group easily. It can be used to group all different resources such as App Services, SQL databases, and storage accounts available in Microsoft Azure. We will consider services that we will use in this chapter for most of the examples.

For example, we need to create resources such as Azure Web Apps, SQL database, and a storage account in West US and provide access to some users. It is painful to assign users to individual resources. Rather, it is more manageable if we can provide group access to all the resources.

This way the resources can be managed in a better way.

  1. To create a resource group, go to Azure Portal https://portal.azure.com and click on Resource Groups in the left sidebar menu.
  2. Click on + Add to create a resource group.
  3. Provide the Resource group name, select Subscription, select Resource group location, and then click on Create:
  1. Wait until the resource group is created:
  1. Click on the AzureFunctions resource group:
  1. Once the Azure Functions resource group is created, click on it and verify the Overview section. As of now, there are no resources in the resource group, hence there are No deployments in the Overview section and No resources to display:
  1. To provide role-based access, click on Access control (IAM). Check the OWNER and other details:
  1. Click on + Add and select Contributor role. Find the member whom you want to give access to this resource group:
  1. Select the member and click on Save:

We will use this resource group in the coming chapters as a logical container for different resources such as Azure Functions and storage.

App Services - Microsoft Azure Web Apps

Microsoft Azure App Services is one of the most popular offering from Microsoft Azure. It is a PaaS. There are four kinds of applications created in App services:

Azure App Services is a PaaS offering that has computing resources and runtime environments managed by Microsoft Azure, while the user is only responsible for applications and configurations relating to Web App and High Availability.

The following are some quick points about Azure Web Apps:

  • App Services run on virtual machines - virtual machines are managed by Microsoft Azure
  • There are five pricing tiers that are available - Free, Shared, Basic, Standard, and Premium
  • It supports applications written in Java, ASP.NET, PHP, Node.js, and Python
  • We can integrate Apps with Visual Studio or GitHub
  • We can create Apps from the Azure portal and also from the command line using Powershell commands; hence, it is easier to automate the creation process
  • We can set Continuous Integration and Continuous Delivery or Deployment using Build and Release of Visual Studio Team Services
  • We can configure auto-scaling and make it available across the regions; we can set high availability as well

Let's look at some basic differences between Azure Virtual Machines and Azure Web Apps:

Microsoft Azure Virtual Machines

Microsoft Azure Web Apps

Offering

Infrastructure as a Service

Platform as a Service

Support

Support for Linux, Windows Server, SQL Server, Oracle, IBM, and SAP

Linux and Windows

Categories

General Purpose

Compute Optimized

Memory Optimized

GPU

High Performance Compute

Free

Share

Basic

Standard

Premium

Cost

Per minute billing

Per minute billing

Virtual Infrastructure Responsibility

User

Microsoft Azure

Out of the Box support for VSTS

No

Yes

Management Overhead

Yes

No

Installation and Configuration required?

Yes; the customer is responsible for managing the resources

Web Apps come with a platform that supports different programming languages; we only need to configure the Application settings

App Service plan

An App Service plan (ASP) is a combination of capacities (instance size and instance count on which the application is hosted) and features. Capacity is directly related to cost and hence it is similar to choosing a pricing tier. There are different capabilities and limits available in pricing plans.

Each ASP can be used for different purposes and they provide different features too. There are five pricing tiers as follows:

  • Free: no scaling
  • Shared: no scaling
  • Basic: SLA - 99.95%; maximum instances for scaling - 3
  • Standard: SLA - 99.95%; autoscale, 5 deployment slots; Geo-distributed deployment, VPN hybrid connectivity, deployment slots, and automated backups; maximum instances for scaling - 10
  • Premium: SLA - 99.95%; 20 deployment slots; autoscale, geo-distributed deployment, VPN hybrid connectivity, deployment slots, and automated backups; maximum instances for scaling - 50

Note

App Service or Azure Web App is the main production slot. In the standard and premium tiers, we can create other deployment slots other than the main slot in which we deploy the application. We can use deployment slots for different environments before deploying applications into the main slot. Slots are not different from a live web app. They have their own set of content and configurations and hostnames. We can swap slots to roll back failures too.

The following are some important points regarding an App Service plan:

  • An App Service plan can be shared by multiple applications.
  • Deployment slots are usually deployed on the same App Service plan.
  • Azure Web Apps configured with an App Service plan are changed, and then these changes affect all the applications hosted on the App Service plan.
  • By default, ASP comes with a single instance. If we increase the instance count, then the applications hosted on a single instance will be hosted on other instances too.
  • The number of instances in ASP is directly associated with the price of Azure Web Apps.

Let's create an App Service plan in Microsoft Azure Portal:

  1. Click on More services in the left sidebar and find App Service plans.
  2. Click on + Add.
  3. Provide the App Service plan name, Subscription, Resource Group, Operating System, Location and Pricing tier, and then click on Create:
  1. Click on Notifications to get the progress details of the App Service plan deployment:
  1. Once App Service plan is created successfully, click on the Overview section to get details about it in the Azure Portal:

We can deploy Azure App Services or Azure Functions on App Service plan.

Azure Active Directory

Azure Active Directory (Azure AD) is a cloud based, multitenant, and highly available identity management service from Microsoft:

We can manage users, groups, multifactor authentication, add an application that an organization is developing for authentication, add an application from the gallery for authentication, add a custom domain, role based access control, and so on:

Application Gallery supports more than 2500 applications at the time of writing this chapter:

The categories include business management, collaboration, construction, content management, CRM, data services, developer services, e-commerce, education, ERP, finance, health, human resources, IT infrastructure, mail, marketing, media, mobile device management, productivity, project management, security, social, supply management, telecommunications, travel, and web design and hosting.

App Insights

Application Insights is a flexible analytics service. It helps us to get insights of performance and usage of application. It can be used for .NET or J2EE-based applications that are hosted on-premises or in the cloud. Let's create Application Insights for a sample application:

  1. Create a sample application and go to its Monitoring section. Click on Application Insights. Select Create new resource and click on OK.

 

  1. We can create a Web test for testing application availability from multiple regions. We can select a ping test or a multistep test to check the availability, and alert criteria can also be configured.
  2. Performance Testing is also a very interesting feature available in App Insights. It is more of a load test based on the number of users over a specific duration.
  3. We will see the how to of both in this book, where we intend to cover monitoring.