Hands-On Azure for Developers - Kamil Mrzygłód - E-Book

Hands-On Azure for Developers E-Book

Kamil Mrzygłód

0,0
41,99 €

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

Microsoft Azure is one of the fastest growing public cloud service providers in the market currently, and also holds the second highest market share after AWS. Azure has a sophisticated set of services that will help you build fault-tolerant and scalable cloud-based applications.
Hands-On Azure for Developers will take you on a journey through multiple PaaS services available in Azure, including App Services, Functions, and Service Fabric, and explain in detail how to build a complete and reliable system with ease. You will learn about how to maximize your skills when building cloud-based solutions leveraging different SQL/NoSQL databases, serverless and messaging components, and even search engines such as Azure Search. In the concluding chapters, this book covers more advanced scenarios such as scalability best practices, serving static content with Azure CDN, and distributing loads with Azure Traffic Manager.
By the end of the book, you will be able to build modern applications on the Azure cloud using the most popular and promising technologies, which will help make your solutions reliable, stable, and efficient.

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

EPUB
MOBI

Seitenzahl: 508

Veröffentlichungsjahr: 2018

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.



Hands-On Azure for Developers
Implement rich Azure PaaS ecosystems using containers, serverless services, and storage solutions
Kamil Mrzygłód
BIRMINGHAM - MUMBAI

Hands-On Azure for Developers

Copyright © 2018 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 author, 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: Gebin GeorgeAcquisition Editor: Shrilekha InaniContent Development Editor: Deepti Thore, Dattatraya MoreTechnical Editor: Sayali ThanekarCopy Editor:Safis EditingProject Coordinator: Jagdish PrabhuProofreader: Safis EditingIndexer: Rekha NairGraphics: Jisha ChirayilProduction Coordinator: Shraddha Falebhai

First published: November 2018

Production reference: 1291118

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

ISBN 978-1-78934-062-4

www.packtpub.com

For Klaudia, who inspires me to develop myself every day. – Kamil Mrzygłód
mapt.io

Mapt is an online digital library that gives you full access to over 5,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

Mapt is fully searchable

Copy and paste, print, and bookmark content

Packt.com

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 author

Kamil Mrzygłód is a skilled software developer, architect, and Microsoft Azure MVP. He is focused on delivering fast, reliable, and flexible cloud solutions based on the Microsoft Azure platform. He has spoken at multiple conferences and meetups, working on open source software (OSS) projects and driving workshops for different people and companies. Over recent years, he has developed an interest in Azure serverless architectures, data analysis, and big data components. Currently, he works at Demant Technology Center in Warsaw. His current goal is to make the world of cloud computing as accessible as it can be so that it's possible to lower the learning curve of this technology and help others start using it.

I would like to thank my editor, Dattatraya More, for his helpful insights and valuable guidance, which helped me a lot while writing this book. I would also like to thank Shrilekha Inani, who gave me the opportunity to become an author and assisted me in all the formal aspects of doing so. Last, but by no means least, I would like to thank my reviewers—you really made this book worth reading by carefully examining whether each chapter made sense.

About the reviewers

Kasam Shaikh, a Microsoft Azure enthusiast, is a seasoned professional with a can-do attitude and 10 years of industry experience working as a cloud architect with one of the leading IT companies in Mumbai, India. He is a certified Azure architect, recognized as an MVP by a leading online community, as well as a global AI speaker, and has authored books on Azure Cognitive, Azure Bots, and Microsoft Bot frameworks. He is head of the Azure INDIA (az-INDIA) community, the fastest growing online community for learning Azure.

Praveen Kumar Sreeram works as an Azure architect at MNC. He has 12 years of experience in the field of development, analysis, design, and delivery of applications of various technologies, including custom web development using ASP.NET and MVC to building mobile apps using the cross-platform technology Xamarin for domains such as insurance, telecoms, and wireless expense management. He has been awarded two times as the Most Valuable Professional CSharpCorner. You can also follow him on Twitter at @PrawinSreeram. His current focus is on analyzing business problems and providing technical solutions for various projects related to Microsoft Azure and .NET Core. He is also an author of a book call Azure Serverless computing cookbook.

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

Hands-On Azure for Developers

Dedication

About Packt

Why subscribe?

Packt.com

Contributors

About the author

About the reviewers

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

Azure App Service

Technical requirements

Creating and deploying Azure App Service

Creating Azure App Service using the Azure Portal

Selecting Azure Web App from available services

Configuring an Azure web app

Creating an App Service Plan

Creating an Azure App Service using Visual Studio

Deploying Azure App Service using FTP

Deploying Azure App Service with user-level credentials

Deploying Azure App Service using app-level credentials

Downloading app-level credentials from the Azure Portal

Configuring WebDeploy in Visual Studio

Creating Azure App Services using Visual Studio Code

Working with different operating systems and platforms

Selecting an operating system

Selecting different platforms

Working with application settings

Different App Service Plans and features

Dev/Test App Service Plans

Production App Service Plans

Isolated App Service Plans

Securing App Services using different security providers

Configuring authentication/authorization in the Azure Portal

Using Azure Active Directory to secure App Services

Using other authentication providers

Diagnostics and monitoring of App Services

The Overview blade

Metrics

Monitoring

Summary

Questions

Further reading

Azure WebJobs

Technical requirements

Creating WebJobs

Creating and deploying WebJobs in Azure Portal

Creating an application in Visual Studio

Deploying a WebJob in the Azure Portal

Deploying WebJobs from Visual Studio

Working with the WebJobs SDK

Calling a job manually

Automatic triggers in WebJobs

Publish a job

Azure WebJobs limitations

Using different file types for WebJobs

Creating and deploying a Node.js application as a WebJob

Deploying a Node.js Azure WebJob from Visual Studio Code

Summary

Questions

Further reading

Deploying Web Applications as Containers

Technical requirements

Working with AKS

Preparing an application

Container Registry and Kubernetes clusters

Pushing a Docker image to Azure Container Registry

Creating a Kubernetes cluster using AKS

Running, scaling, and updating an application in AKS

Solving problems with authentication

Scaling a cluster

Updating an application

Azure Container Instances

Creating and deploying an application and container

Pushing an image to Azure Container Registry

Deploying an application to ACI

Web App for Containers

Creating a web app hosted in a container

Deploying a custom application

Summary

Questions

Further reading

Distributed Applications and Microservices with Service Fabric

Technical requirements

Understanding microservices

Monolith versus microservices

Microservice approach

Using different languages and frameworks

Scaling and updating services individually

Using well-designed interfaces and protocols

Dealing with state

Diagnosing and monitoring microservices

Containers, services, and actors in SF

Containers

Creating a cluster

Deploying a container

Packaging a service

Reliable services

Creating a SF application

Deploying an application to the cloud

Reliable actors

Creating a project with actors

Creating an actor's client

Communication between services

Creating a communication channel

Clusters in SF

Cluster security

Node-to-node security

Client-to-node security

Scaling

Scaling a cluster up or down

Monitoring and diagnostics

Application monitoring

Cluster monitoring

Health monitoring

Summary

Questions

Further reading

Using Azure Search

Technical requirements

Creating an Azure Search service

Using Azure Portal

Full-text search in Azure Search

Sending a request

Linguistic analysis in full-text search

Analyzers in Azure Search

Analyzer selection

Indexing in Azure Search

Importing more data

Push model

Pull model

Cognitive search – adding AI to the indexing workload

Configuring Cognitive Search

Summary

Questions

Further reading

Mobile Notifications with Notification Hub

Technical requirements

Reasons to use Notification Hub

Challenges for application design

Push notification architecture

Direct connection

Queued communication

Triggered communication

Registering devices in Notification Hub

Notification Hub device registration

Creating a Notification Hub

Registering in an application

Checking available registrations

Using installations

Sending a notification

Sending a test notification

Test notification in Azure Portal

Test notification in the SDK

Using the SDK to send a notification

Rich content notifications

Creating and sending a rich content notification

Summary

Questions

Further reading

Serverless and Azure Functions

Technical requirements

Understanding Azure Functions

Being "serverless"

Responsibilities of cloud vendors

Pricing model

Azure Functions concepts

Function app

Functions

Triggers and bindings

Pricing models

Scaling

Scaling in the consumption model

Scaling in the App Service model

Configuring the local environment for developing Azure Functions

Starting with Azure Functions locally

Creating a function

Using Visual Studio

Using Azure Portal

Azure Functions features

Platform features

Security

Monitor

Host.json

Publish

Workflow in Azure Functions – Durable Functions

Orchestrations and activities

Orchestration client

Orchestration history

Timers

External events

Integrating functions with other services

Function file

Input/output bindings

Custom bindings

Summary

Questions

Further reading

Integrating Different Components with Logic Apps

Technical requirements

What is Azure Logic Apps?

Azure Logic Apps – how it works

Azure Logic Apps – advantages

Connectors for Logic Apps

Connector types

Built-in connectors

Managed API connectors

On-premises connectors

Integration account connectors and enterprise connectors

Creating Logic Apps and integrating services

Creating Logic Apps in Azure Portal

Working with Azure Logic Apps in Visual Studio

B2B integration

Starting B2B integration in Azure Logic Apps

Summary

Questions

Further reading

Swiss Army Knife - Azure Cosmos DB

Technical requirements

Understanding Cosmos DB

Creating a Cosmos DB instance in the portal

Using Azure Cosmos DB in Visual Studio

Pricing in Azure Cosmos DB

Partitioning, throughput, and consistency

Partitions in Azure Cosmos DB

Throughput in Azure Cosmos DB

Consistency in Azure Cosmos DB

CosmosDB data models and APIs

SQL

MongoDB

Graph

Table

Cassandra

Different features of CosmosDB

Account level throughput

Database level throughput

Firewall and virtual networks

Azure Functions

Stored procedures

User-defined functions and triggers

Summary

Questions

Further reading

Reactive Architecture with Event Grid

Technical requirements

Azure Event Grid and reactive architecture

Reactive architecture

Topics and event subscriptions

Event sources

Event handlers

Topics and subscriptions

Connecting services through Azure Event Grid

Creating Azure Event Grid in Azure Portal

Azure Event Grid security

Creating a subscription

Publishing custom events to Azure Event Grid

Event gateway concept

Handling a custom event

Integrating Azure Functions with Azure Event Grid

EventGridTrigger in Azure Functions

Testing Azure Event Grid and Azure Functions

Summary

Questions

Further reading

Using Azure Storage - Tables, Queues, Files, and Blobs

Technical requirements

Using Azure Storage in a solution

Different Azure Storage services

Different types of storage account

Securing Azure Storage

Replication

Storing data with Azure Storage Tables

Creating an Azure Storage service

Managing Table Storage

Storing data in Table Storage

PartitionKey

RowKey

Timestamp

General rules for entities

Querying data in Table Storage

Table API in Azure Cosmos DB

Implementing fully managed file shares with Azure Files

Azure Files concepts

Working with Azure Files

Blob Storage versus Azure Files

Queues in Azure Queue Storage

Queue Storage features

Developing an application using Queue Storage

Object storage solution – Azure Storage Blobs

Blob Storage concepts

Inserting data into Blob Storage

Containers and permissions

Blob Storage: additional features

Summary

Questions

Further reading

Big Data Pipeline - Azure Event Hub

Technical requirements

Azure Event Hub service and concepts

Azure Event Hub concepts

Azure Event Hub durability

Working with Azure Event Hub

Creating an Azure Event Hub in the Azure portal

Working with Azure Event Hub in the portal

Developing applications with Azure Event Hub

Azure Event Hub security

Event publishers

IP filters

Azure Event Hub Capture feature

How Azure Event Hub Capture works

Enabling Event Hub Capture

Summary

Questions

Further reading

Real-Time Data Analysis - Azure Stream Analytics

Technical requirements

Azure Stream Analytics introduction

Stream ingestions versus stream analysis

Azure Stream Analytics concepts

Input and output types

Create Azure Stream Analytics in Azure portal

Adding an input

Adding an output

Azure Stream Analytics query language

Writing a query

Event ordering, checkpoints, and replays

Event ordering

Checkpoints and replays

Summary

Questions

Further reading

Enterprise Integration - Azure Service Bus

Technical requirements

Azure Service Bus fundamentals

Azure Service Bus versus other messaging services

Azure Service Bus and Azure Storage Queues

Azure Service Bus in Azure portal

Queues, topics, and relays

Queues

Topics

Relays

Azure Service Bus design patterns

Developing solutions with Azure Service Bus SDK

Azure Service Bus security

Managed Service Identity

RBAC

Advanced features of Azure Service Bus

Dead lettering

Sessions

Transactions

Handling outages and disasters

Disaster recovery

Handling outages

Summary

Questions

Further reading

Using Application Insights to Monitor Your Applications

Technical requirements

Using the Application Insights service

Logging data in the cloud

Azure Application Insights fundamentals

Creating Azure Application Insights in the portal

Monitoring different platforms

.NET

Node.js

Azure Functions

Analytics module

Accessing the Analytics module

Application Insights automation

Alerts

Summary

Questions

Further reading

SQL in Azure - Azure SQL

Technical requirements

Differences between Microsoft SQL Server and Azure SQL

Azure SQL fundamentals

Advanced Azure SQL features

SQL Server on VMs

Creating and configuring Azure SQL

Creating an Azure SQL instance

Azure SQL features in the portal

Security

Firewall

Advanced Threat Protection

Auditing

Dynamic Data Masking

Scaling Azure SQL

Single database

Elastic pool

Read scale-out

Sharding

Monitoring and tuning

Monitoring

Tuning

Summary

Questions

Further reading

Big Data Storage - Azure Data Lake

Technical requirements

Understanding Azure Data Lake Store

Azure Data Lake Store fundamentals

Creating an Azure Data Lake Store instance

Storing data in Azure Data Lake Store

Using the Azure portal to navigate

Filter

New folder

Upload

Access

Files and folders

Microsoft Azure Storage Explorer

Using SDKs

Security

Authentication and authorization

RBAC

POSIX ACL

Network isolation

Best practices

Performance

Security

Resiliency

Data structure

Summary

Questions

Further reading

Scaling Azure Applications

Technical requirements

Autoscaling, scaling up, scaling out

Autoscaling

Scaling up and scaling out

Scaling Azure App Services

Manual scaling

Autoscaling

Scaling Azure Functions

Scaling serverless applications

Scaling Azure Functions

Scaling Azure Service Fabric

Scaling a cluster manually

Using Azure SDK to scale your cluster

Summary

Questions

Further reading

Serving Static Content Using Azure CDN

Technical requirements

Azure CDN fundamentals

Working with CDNs

Creating an Azure CDN in the portal

Optimization and caching

Configuring the endpoint

Compression

Caching rules

Geo-filtering

Developing applications with Azure CDN

Configuring Azure App Service with Azure CDN

Summary

Questions

Further reading

Distributing Load with Azure Traffic Manager

Technical requirements

Azure Traffic Manager fundamentals

Functions of Azure Traffic Manager

Creating Azure Traffic Manager in the Azure portal

Routing method – performance

Routing method – weighted

Routing method – priority

Routing method – geographic

Routing method – MultiValue

Routing method – subnet

Working with Azure Traffic Manager in the Azure Portal

Configuration

Real user measurements

Endpoints

Monitoring

Nslookup

Traffic view

Summary

Questions

Further reading

Tips and Tricks for Azure

Technical requirements

The Azure CLI and Cloud Shell

The Azure CLI

Cloud Shell

Locks

Creating and managing locks

Naming conventions

Finding the best naming convention

Resources in Azure

Azure Resource Explorer

Summary

Questions

Further reading

Assessments

Chapter 1: Azure App Service

Chapter 2: Azure WebJobs

Chapter 3: Deploying Web Applications as Containers

Chapter 4: Distributed Applications and Microservices with Service Fabric

Chapter 5: Using Azure Search

Chapter 6: Mobile Notifications with Notification Hub

Chapter 7: Serverless and Azure Functions

Chapter 8: Integrating Different Components with Logic Apps

Chapter 9: Swiss Army Knife – CosmosDB

Chapter 10: Reactive Architecture with Event Grid

Chapter 11: Using Azure Storage – Tables, Queues, Files, and Blobs

Chapter 12: Big Data Pipeline – Azure Event Hub

Chapter 13: Real-Time Data Analysis – Azure Stream Analytics

Chapter 14: Enterprise Integration – Azure Service Bus

Chapter 15: Using Application Insights to Monitor Your Applications

Chapter 16: SQL in Azure – Azure SQL

Chapter 17: Big Data Storage – Azure Data Lake

Chapter 18: Scaling Azure Applications

Chapter 19: Serving Static Content Using Azure CDN

Chapter 20: Distributing Load with Azure Traffic Manager

Chapter 21: Tips and Tricks for Azure

Other Books You May Enjoy

Leave a review - let other readers know what you think

Preface

Cloud technology is currently one of the most popular trends within the IT industry. Every day, a new company embarks on its journey with cloud computing, distancing itself from traditional on-premise setups, which have a tendency to hinder quick development and impede scaling operations. As the modern world requires us to adjust rapidly to changing expectations and dynamic workloads, knowledge of how to develop applications in the cloud is becoming more and more valuable.

You are holding in your hands a book that will guide you through the different capabilities and services of one of the most popular cloud offerings around—Microsoft Azure. We will focus mostly on Platform-as-a-Service (PaaS) components, which allow you to skip the cumbersome process of provisioning the infrastructure and focus directly on configuring various features and deploying your code, so that your application will be scalable, highly available, and resilient. The goal of each chapter is to give you a better understanding of multiple cloud patterns, connections, and integrations, so you can quickly start your very own project with an understanding of which Azure service you should use in this particular architecture.

Who this book is for

This book is designed to act as a journey through different Azure PaaS offerings. It covers many basic and intermediate concepts of different services, an understanding of which is crucial when it comes to developing reliable and robust solutions based on the Microsoft cloud platform. The main audiences are developers and IT pros who have just started working with Azure, or who want to do so, and who are seeking a detailed guide to enable them to extend their cloud skills.

What this book covers

Chapter 1, Azure App Services, covers how to work with and develop web applications, monitoring, and diagnosis.

Chapter 2, Azure WebJobs, explains how to develop jobs co-hosted with Azure App Services.

Chapter 3, Deploying Web Applications as Containers, explains how to develop a web application and host it within a container using Azure App Services.

Chapter 4, Distributed Applications and Microservices with Service Fabric, is a basic introduction to a microservice platform called Azure Service Fabric.

Chapter 5, Using Azure Search, explains how to develop a search engine using Azure Search and utilize it in your application.

Chapter 6, Mobile Notifications with Notification Hub, covers the development of applications that leverage push notifications.

Chapter 7, Serverless and Azure Functions, outlines the building of applications based on the FaaS model.

Chapter 8, Integrating Different Components with Logic Apps, discusses the integration of different parts of your system using Azure Logic Apps.

Chapter 9, Swiss Army Knife - Azure Cosmos DB, covers the utilization of a modern storage solution with multiple APIs and a consistency model.

Chapter 10, Reactive Architecture with Event Grid, demonstrates how to reverse a control with another serverless Azure component called Azure Event Grid.

Chapter 11, Using Azure Storage - Tables, Queues, Files, and Blobs, covers a common Azure storage service with many different features.

Chapter 12,Big Data Pipeline - Azure Event Hub, explains how to create applications handling thousands of requests per second.

Chapter 13,Real-Time Data Analysis - Azure Stream Analytics, explains how to perform analyses on a stream of data.

Chapter 14,Enterprise Integration - Azure Service Bus, introduces an enterprise-class Azure service for messaging.

Chapter 15,Using Application Insights to Monitor Your Applications, explains how to use Azure Application Insights to log data from different Azure services as well as from your own applications.

Chapter 16,SQL in Azure - Azure SQL, introduces a relational database PaaS offering that is available in Azure.

Chapter 17,Big Data Storage - Azure Data Lake, introduces a limitless storage service for storing schemaless data.

Chapter 18,Scaling Azure Applications, covers more advanced topics on scaling applications and how scaling works in Azure.

Chapter 19,Serving Static Content Using Azure CDN, introduces your very own CDN hosted within Azure.

Chapter 20, Distributing Load with Azure Traffic Manager, explains how to achieve high availability and offload traffic using Azure Traffic Manager.

Chapter 21, Tips and Tricks for Azure, provides a bunch of tips for working with Azure and Azure resources.

To get the most out of this book

Activate your Azure subscription (whether a trial version, MSDN subscription feature, or a commercial one).

Since most of the examples are based on the .NET stack, some prior knowledge of this technology will make things easier for you, although, where possible, other technology stacks are also included, while a basic understanding of HTTP concepts (such as the protocol or communication model) will be an advantage. A basic understanding of container-related topics will also be beneficial.More advanced topics and detailed instructions will often be included in theFurther readingsections. Make sure you cover them all after finishing exercises from this book.

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.packt.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 & Errata

.

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 athttps://github.com/PacktPublishing/Hands-On-Azure-for-Developers. 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 athttps://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://www.packtpub.com/sites/default/files/downloads/9781789340624_ColorImages.pdf.

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.packt.com/submit-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.

Azure App Service

Azure App Service is one of the biggest and most commonly used services available in the Azure cloud. It allows for easy development of web applications with multiple features available (such as support for different platforms, including .NET, PHP, and Java), manual and automated scaling, and different performance options. It's a general platform and runtime that fuels other services, such as WebJobs and Azure Functions.

In this chapter, you will learn about the following:

Creating and deploying Azure App Service

Working with different operating systems and platforms

Choosing the right App Service Plan and what their features

are

Securing App Service using different security providers

Diagnosing and monitoring your applications

Technical requirements

To perform the exercises in this chapter, you will need the following:

Access to an Azure subscription

Visual Studio 2017 with Azure development workload installed

Visual Studio Code installed (available at

https://code.visualstudio.com/

)

Creating and deploying Azure App Service

To get started with Azure App Service, you have to learn how to create that service and deploy your code. You will see how Azure provides many different ways for doing so, and each path can be easier or harder, depending on your current needs and the specification of your application. However, the strength of a cloud and Platform as a Service (PaaS) offering lies in the straightforward and intuitive process of provisioning new components of your system.

Creating Azure App Service using the Azure Portal

To begin with App Service, I will show you how you can create your very first web app using the Azure Portal. In fact, all you need is your mouse and keyboard (because each application has to have a name)—neither external hardware nor detailed configuration information is required here, because Azure will do everything for you.

Selecting Azure Web App from available services

To create Azure App Service in the Azure Portal, you first have to find it in the list of available services. The easiest way to do so is to click on + Create a resource button and search for Web App:

Instead of using the + Create a resourcebutton, you can click on App Services—it will forward you to a different view, where you can create an App Service by clicking on the + Addbutton. This is true for all of the most popular Azure services, such as SQL databases, virtual machines, and storage accounts.

As you can see, the Azure Portal tries to help you find the service most relevant to the search string. When you click on the Web Appitem, you will see another screen containing multiple similar items, all related in some way to the one you are searching for:

For the purpose of this exercise, select Web App, and then click on the Create button at the right bottom of the screen.

In the beginning, it is always easier to select the most generic option when it comes to choosing a service. When you gain more experience and become more familiar with available services, you will see that Azure offers many useful preconfigured setups (such as an integrated Web App and SQL database), which can be used to shorten development and configure all services in one place.

Configuring an Azure web app

When you click on the Create button, you will see a screen where you can enter all the information needed to create a web app. All required fields are marked using an * (asterisk) symbol:

As you can see, when creating a web app, we have to fill almost all fields (with a little exception regarding the Application Insightsradio button, which we will cover in the next chapters). Let's focus on each field separately, so we have a better understanding of how they work:

App name

: This field represents the domain name of your application. It is important to select both a unique and valid name, as it cannot be changed later on. Please note that you can easily attach your own custom domain if needed.

Subscription

: If you have access to more than one subscription, you will be given an opportunity to select the right one for this particular resource. Thanks to that, you will be able to differentiate the cost between, for example, different projects.

Resource Group

: In Azure, each resource has to be a part of a logic container, called a resource group. This does not imply any additional cost by itself, so you do not have to worry about creating multiple r

esource groups.

OS

: Currently in Azure, you can create a web app using the different operating systems of

Windows

,

Linux

, or

Docker

containers. This choice can impact both cost and performance, so make sure you have chosen the right operating system for your needs.

App Service plan/Location

: App Services in Azure are directly linked to App Service Plans, which provide different features and performance depending on the option you choose.

It is always a good practice to leverage resource groups and separate your resources using a specific filter, such as the lifetime of resources, or the given environment (that is, production, staging, or testing). Resource groups gives you better control over deployed services and allows for more granular control over who can access a resource.

Since you are just starting with Azure, you probably do not have any App Service Planscreated. As we cannot create an App Service without an App Service Plan, we will sort this now.

Creating an App Service Plan

When you click on App Service plan/Location,you will see a screen with the + Create newbutton, allowing for the creation of a new App Service Plan. It should look like this:

As you can see, we have to enter three fields:

App Service plan

: This is the name of your App Service Plan, which has to be unique within a resource group.

Location

: Thanks to this setting, we can locate our App Service Planin a specific region. This sometimes implies different features are available.

Pricing tier

: When you click on this item, you will see another screen presenting available features for different available tiers. This choice is really important feature-wise, and will depend in most cases on the environmental characteristics you are planning (such as

Dev / Test

environments,

Production

applications, whether you need deployment slots or not, and so on):

As you can see in the preceding screenshot, we have three categories of App Service Plans:

Dev / Test

: This one contains F, D, and B tiers (which stand for free, shared, and basic). They are designed for simple dev/test scenarios and lightweight web applications that do not need features such as autoscaling or backups.

Production

: This offers powerful machines and advanced features that are useful in many realistic scenarios,

such as

APIs, e-commerce, and popular portals.

Isolated

: This uses the same hardware as the

Production

tier, but with even more features and possibilities to isolate your web apps from external access. This is the most expensive category, but can be helpful when creating systems that cannot be made available publicly.

It is important to remember that tiers F and D have a limited amount of computing time per day. That means that once you exceed the limit (60 minutes for the F tier, and 240 minutes for the D tier) of your processing time, your application will become unavailable and be suspended until the next day.

For the purpose of this exercise, I would recommend selecting any tier from the Dev / Testcategory. Once you are satisfied with the option you've selected, you can click the Apply button. My configuration, for example, looks like this:

Remember that you can always upgrade (or scale up) the instance of your App Service Plan, for example, when you need a specific feature or the popularity of your application has grown. This is one of the biggest advantages of cloud over on-premises, where you would have to buy and set up new machines on your own.

Now, you can click OK, and you will return to the Web Appblade, where you can enter missing fields. Here, you can see the whole configuration of my web app:

Now the only thing left is to click on the Create button and wait several seconds for the creation of a new resource. During this time, Azure will validate the template and parameters, and orchestrate multiple underlying controllers to create a service. Once a new resource is created, you should see a notification and be able to see in your resources. To quickly validate this, click on the All resourcesbutton on the left and filter all of them using, for example, the name of the App Serviceyou have created:

Creating an Azure App Service using Visual Studio

If you do not want to create your web apps using the Azure Portal, you can use Microsoft Visual Studio, which has built-in integration for many different Azure services.

This exercise was created using Microsoft Visual Studio 2017 (15.6.4) with Azure workloads installed. If you want to configure your instance and ensure everything is set up correctly, please follow the short tutorial available at https://docs.microsoft.com/en-us/dotnet/azure/dotnet-tools?view=azure-dotnet&tabs=windows.

In Visual Studio, click on File | NewProject. This will display a New Projectwindow, where you can find plenty of different templates for starting with a new application. Because we are interested in cloud projects, let's start with the Cloud category:

Since we are working with App Services in this chapter, the template we are interested in is ASP.NET Web Application (.NET Framework). The other valid option here is also ASP.NET Core Web Application—feel free to use it if you feel confident enough to work with the latest .NET releases, as we will cover both scenarios. When you are satisfied with your choice, click OK.

The next step is the selection of the proper template. Here, you have multiple options, such as the following:

Empty

: The most simple option, which lets you have full control over installed packages and overall structure

Web Forms

: The oldest available framework for building web applications, using many built-in controls with data access

MVC

: A well-known

model-view-controller

(

MVC

) architecture, which took the place of

Web Forms

Web API

: A template for creating RESTful HTTP services using the .NET programming stack

Single Page Application

:This template comes with plenty of additional tools for building client-side interactions

All the preceding options should be more or less familiar to you. However, thanks to installing the Azure toolset, you should have access to two additional templates:

Azure API App

: This offers additional integrations with different Azure services such as Azure AD, API Management, and Logic apps

Azure Mobile App

: A template for building mobile backends

However, we will cover those two in the next sections of this chapter. For now, to proceed, let's select MVC,as this is the most common and simplest of all templates listed here. Use the default options for this template and clickOK.

You have probably noticed an additional button, which I have not described, Change Authentication. It allows for selecting the method used for authenticating access to your web application. We will cover that feature in the section describing the security of web apps in Azure.

After several seconds, Visual Studio should generate a project based on the selected template. I believe it should look familiar to you, as it is not that different to a traditional web application created from an MVC template. I am sure you cannot wait to see whether it works—do not wait any longer, and press F5 to start the application.

You should see a screen similar to mine:

As you can see, it is the same generic template that you would see when starting with a traditional project. The question is, how can we deploy it to Azure to have our website working in the cloud?

Let's stop our website running locally and go back to Visual Studio for a moment. When you right-click on a project icon, you will see a context menu. There, between multiple different options, you can click on Publish...:

Since this is a cloud project, you will see additional options besides IIS, FTP, and Folder:

App Service

: This is for deploying your application to a PaaS service

Azure Virtual Machines

: This is for deploying your application to a virtual machine that you have configured

Because the topic of this book is PaaS services, we will not cover deploying a web app to a virtual machine. However, if you are interested in doing so, proper instructions are available at https://github.com/aspnet/Tooling/blob/AspNetVMs/docs/create-asp-net-vm-with-webdeploy.md.

For now, let's select App Service. You should see two different options:

Create new

: For deploying an application to a freshly created App Service

Select existing

: This option is only useful if you have already deployed your site

Because we are just starting, the option we are interested in is Create new. After clicking on Publish..., you will see another screen, where you can enter all the required parameters. If you read the previous section about creating an App Service using the Azure Portal, some fields should look familiar—in fact, you are doing the very same thing as you would do in the portal. If you skipped this section, I strongly recommend that you go back and read the descriptions. After configuring my web app, my screen looks like this:

Remember that you can create both resource groups and App Service Plans directly from the preceding screen. If you do not like the options listed there, you can click on the New...button, which will guide you through the process of creating a new resource. This is another advantage of tools such as Visual Studio, as you do not have to leave your programming environment to work with Azure.

If you are satisfied with the current configuration, the last thing left is to click on the Create button and wait a moment for the application deployment to complete. Additionally, Visual Studio will prepare a publish profile that you can reuse whenever you want to. We will have a look at it, as it will help us in the next section of this chapter. Once deployment is completed, you should see your web application open automatically in your default browser:

Congratulations! You have just created and deployed your very first App Service. If you take a look at the URL, you'll see that it contains the name you set in the Visual Studio wizard. All web apps in Azure can be accessed using the following URL format:

http(s)://{appservicename}.azurewebsites.net

This also explains why a name has to be unique: since, by default, all web applications hosted as Azure Web Apps are available publicly, you have to select a name that is not already in use in another URL. In the next section, we will try to use FTP to deploy our application, as an alternative to using Visual Studio.

Deploying Azure App Service using FTP

Using Visual Studio for deployments is a good idea for testing things and development, but for sure, it cannot be used for deploying production environments. The easiest option to upload files to App Service is FTP, which is already integrated with this particular Azure resource.

Deploying Azure App Service with user-level credentials

When you go to the Azure Portal and select the Web App you created previously, take a look at the Overview screen—you will see plenty of information regarding this service, such as current Status, Location, and URL. Among all that information, there is an FTP section containing three different parameters:

FTP/deployment username

: A name that you will use when connecting to your Web App using FTP client

FTP hostname

: A host that should be used when creating an FTP connection

FTPS hostname

: The same host as the previous one, but allowing for secure connection

My App Service currently looks like this:

All FTP information can be found in the bottom-right corner of the whole section. What we need now is the FTP client that we will use to connect to the server. I do not have any particular recommendation when it comes to selecting such an application. Personally, I prefer using FileZilla for managing my FTP connections and file transfers. You can, however, use whichever client you like, as all are quite similar regarding functionality. Before we start uploading files to the server, we need one more thing, a password for the user. To generate a new password, go to the Deployment credentialsblade, which can be found on the left in the DEPLOYMENT section of App Servicefeatures:

Here, you can set two fields:

Username for FTP user

Password for this particular user

You may wonder how this is connected to the previous username, which can be found on the Overview screen. The difference is quite simple: using Deployment credentials,you are creating a new user that will be used for all applications in all subscriptions associated with your Microsoft Azure account. This has the implication that you will be able to use the very same credentials for each App Service you deploy. This is not ideal for every scenario you will face, but for the purpose of this exercise, let's set a user and use it for deployment. In the next part of this section, I will show you how to retrieve credentials from a Publish Profile generated by Visual Studio. Once you enter a username and a password, press Save. Now, we can go to the FTP client and use these credentials for setting a connection. Here, you can see my configuration (note that your username has to be in the following format: <appservicename>\<ftpusername>):

Once you connect to a server, you will see a list of available directories. The very first level contains the following:

LogFiles

: Files containing diagnostic information regarding running App Service

site

:

Your Web App working files are stored here

We will cover LogFiles in the next sections of this chapter, describing monitoring and diagnosing an application. For now, we are interested in the site folder. When you enter it, you will see other directories: deployments, locks, and wwwroot. The last one should be familiar for those of you who have worked with IIS, as this is the most common name of the folder containing a web application. In fact, this is the working directory of your App Service, where all necessary files should be uploaded. Here, you have the full structure of an empty web app:

Now that you know how App Service is structured, you can deploy your files and see whether or not it works. If you want, you can reuse a project from the previous exercise, or upload a brand new website.

If you want to reuse files, you can publish a project once again, but this time, instead of publishing it directly to Azure, create a new Publish Profile and use a folder as the target. Once Visual Studio finishes creating the package, simply copy files from the output directory to the FTP location using your FTP client.

Here are the files from a previous project of mine uploaded to my FTP server:

Now, when I go to the URL of my website, I will see a working application:

Great—you have just learned how to leverage the FTP feature of App Services to deploy an application from any location and environment. However, as I mentioned earlier, we are using user-level credentials, which will be the same for all web apps that you deploy within your subscription. How do we achieve the same result using an app-level username and password?

Deploying Azure App Service using app-level credentials

There are two ways to deploy an application using app-level credentials:

Download them from the Azure Portal

Configure WebDeploy in Visual Studio

Downloading app-level credentials from the Azure Portal

When you go to your App Service and click on the Overview blade, you will see the Get publish profilebutton at the top, as shown in the following screenshot:

Now, when you click on it, your browser will download a .PublishProfilefile. Please open it to check its content. Here is an example file from my web app:

<?xml version="1.0" encoding="UTF-8"?> <publishData> <publishProfile profileName="cloudcomrade01 - Web Deploy" publishMethod="MSDeploy" publishUrl="cloudcomrade01.scm.azurewebsites.net:443" msdeploySite="cloudcomrade01" userName="$cloudcomrade01" userPWD="LEebknaDdg0KS6SgScLuXlwtzxvwYway7ssoKxCSkCLi6Gw0HRyt2iEGMLbP" destinationAppUrl="http://cloudcomrade01.azurewebsites.net" SQLServerDBConnectionString="" mySQLDBConnectionString="" hostingProviderForumLink="" controlPanelLink="http://windows.azure.com" webSystem="WebSites"> <databases /> </publishProfile> <publishProfile profileName="cloudcomrade01 - FTP" publishMethod="FTP" publishUrl="ftp://waws-prod-am2-197.ftp.azurewebsites.windows.net/site/wwwroot" ftpPassiveMode="True" userName="cloudcomrade01\$cloudcomrade01" userPWD="LEebknaDdg0KS6SgScLuXlwtzxvwYway7ssoKxCSkCLi6Gw0HRyt2iEGMLbP" destinationAppUrl="http://cloudcomrade01.azurewebsites.net" SQLServerDBConnectionString="" mySQLDBConnectionString="" hostingProviderForumLink="" controlPanelLink="http://windows.azure.com" webSystem="WebSites"> <databases /> </publishProfile> </publishData>

As you can see, it is a simple XML file containing plenty of useful information. What we are interested in currently is both the userName and userPWD properties. Those are what we have been searching for—app-level credentials automatically created on App Servicecreation. You can use these instead of the user-level ones that we created previously.

Configuring WebDeploy in Visual Studio

To check how to configure WebDeploy in Visual Studio, please go through all steps from the beginning of Creating an Azure App Service using Visual Studio section about publishing an application from this IDE. If you have done that, go once more to the Publish screen.

If you want to import a publish profile from the previous section, then on the Publish screen, you can click on the New Profile...button and then select the Import Profile...option, which allows you to select a profile file generated previously.

When you click on the Configure button, you will see another window containing the whole configuration of your deployment:

As you can see, it contains a completely different set of information, which does not reflect the user-level settings you have configured.

Please do remember the difference between user-level and app-level credentials. Note that multiple users with access to a given app can use their own user-level credentials individually. What is more, to be able to use app-level credentials, you have to have at least a Contributor role on a specific App Service. If you are only a Reader, you will not able to access those credentials.

The choice between app-level and user-level credentials depends solely on the process of delivering your application. In most cases, you don't need to check by checking and setting them, as tools such as Visual Studio or Azure DevOps (formerly Visual Studio Team Services) obtain and use them implicitly. App-level credentials are often only used when we are in need of manual deployment.

You can always reset app-level credentials (for instance, if current ones should be revoked, because of some kind of security issue) from the Overview blade. Next to the Get publish profilebutton, you can find the Reset publish profile option, which will set a new username and password.

Creating Azure App Services using Visual Studio Code

Microsoft Visual Studio is not the only available IDE that allows you to work with Azure App Services. Because this Azure service supports different technology stacks, including .NET, JS, PHP, Java, and so on, you can easily leverage its capabilities to host different websites using different runtimes. For instance, let's assume that we have the following PHP code that displays a Hello World message:

<?phpecho('Hello world from Azure App Service - PHP here!');?>

Such a simple PHP application can be easily created in any available IDE that supports the PHP language. For the purpose of this exercise, I chose Visual Studio Code, an open source editor, as it can easily beextended using many different plugins. To make things easier, you can install the following extensions:

With this plugin installed, you will be able to easily deploy your applications from within the IDE, without the need to go to the portal or use other methods. To push the application to the cloud, you have to go to the AZURE tab and find the APP SERVICEsection.

Before the first use of these extensions, you may need to authenticate them. Follow the displayed instructions and Visual Studio Code will connect to your subscriptions.

Before we deploy our simple PHP application, we have to create an Azure App Service. To do so, you will have to click on the Create New Web App...button:

The wizard is a little bit different than in Microsoft Visual Studio, as it acts similarly to a command line, where you provide all fields and information one after another. In Visual Studio Code, you will have to enter the following:

The Azure App Service name

The operating system of your choice

The runtime version

In this particular example, I specified the following:

handsonazure-euw-appservice

Linux

PHP 7.2

Once the provisioning is complete, Visual Studio Code will ask you whether to deploy the application. Select OK,and then choose the folder to deploy to:

Once everything is set and ready, you will see a notification informing you that you are now able to browse the website:

When you click on the Browse Websitebutton, you will be forwarded to the freshly deployed web application. Note that this extension allows you to directly manage the service from within the IDE, and gives you access to different features, including application settings, deployment slots, and Azure WebJobs (the latter of which is described in Chapter 2, Azure WebJobs). Here, you can see the working example hosted within Azure:

The important thing here is that by using the same path, you will be able to host a variety of different runtimes inside different Azure App Services. It doesn't matter whether it is a Java application, a Python script, or a Node.js backend—they are all supported and can be easily developed using IDEs such as Visual Studio Code.

When using Visual Studio Code with the presented extension, you might want to have more control over the creation of a resource. To enable Advanced Creation, go to the File | Preferences | Settings window, find the Extensionssection, and then click on the App Service: Advanced Creation checkbox.

Working with different operating systems and platforms

Currently, App Services supports a couple of different configurations when it comes to selecting operating system, runtime, and a platform. The following are some of the possible options for running your website using App Services:

.NET Core

.NET Framework

Node.js

PHP

Java

Python

Static HTML website

Additionally, you can select a platform (32-bitor 64-bit), HTTP version (1.1 or 2.0), and underlying operating system (Windows, Linux, or Container). Let's start by selecting a proper operating system for our application.

Selecting an operating system

To select an operating system to run your web app, we have to create a new application in Azure. Currently, there is no possibility to change this setting after an App Service is created. To create a new website, go to the Azure Portal and click on + Create a resource. On the new screen, search for Web Appand select the first item displayed (or just return to the beginning of the Selecting Azure Web App from available services section and perform all the steps mentioned there).

On the Web App - Createscreen, you have an OS field. You'll have three options:

Windows

: The most common option for .NET applications, suitable for running .NET Framework, Java, Node.js, or PHP sites.

Linux

: If you have an application written in .NET Core, you can leverage this

operating system

and its unique features. Additionally, you can run Java, Node.js, PHP, and Python applications as well.

Docker

: Offers Web App for Containers, which we'll cover later in this book. Besides running all of the previous platforms, it allows hosting applications written in languages not currently supported in App Services (such as Go, for example).

The choice is yours. Each operating system has different characteristics: Linuxis perfect for running Python applications, as Windows has some performance issues regarding this language; on the other hand, you may have many websites written in .NET Framework, which are optimized for Windows systems. Each of the operating system options also has different pricing. Let's compare Windows and Linux here:

BASIC

STANDARD

PREMIUM

ISOLATED

Price per hour (Linux)

$0.071

$0.095

$0.19

N/A

Price per hour (Windows)

$0.075

$0.10

$0.20

$0.40

As you can see, there are small differences between these two operating systems. More importantly, Linux does not currently support theFree and Shared tiers. The Isolated tier is currently in public preview, and should not be used for production workloads, but this, of course, can change in the future. When you have considered all the pros and cons, you can create an App Service powered by the operating system of your choice.

Selecting different platforms

In the previous section, you learned how to choose a proper operating system for your application. This is, of course, not everything needed to run a website—you have to also enable a specific language if you want to deploy, for example, PHP code. To do so, go to your App Service (you have many options by which to do this: either choose App Servicesfrom the Azure Portal menu on the left and select your Web App, or go to the resource groupyou created by choosing it from Resource Groupsblade) and then select the Application settings blade:

Initially, you could feel a bit overwhelmed by all those options available, but soon, as you gain more and more experience, all will become clear. You might have noticed the Upgrade to enablelinks here—some features, such as Platform or Always On,are only available from the B1tier upward.

Remember that the Always Onfeature could become crucial in some specific scenarios, as it defines whether your application is always running or not (so it can become idle when no one uses it). As you will learn in the coming sections, setting Always On to On is required when running, for example, continuous Web Jobs or Azure Functions.

Currently, we are interested in all options mentioning a programming language. These options include the following:

.NET Framework version

PHP version

Python version

Java version