Practical Azure Application Development - rd.springer.com

Practical Azure Application Development A Step-by-Step Approach to Build Feature-Rich Cloud-Ready Solutions Thurupathan Vijayakumar...

1 downloads 591 Views 149KB Size
Practical Azure Application Development A Step-by-Step Approach to Build Feature-Rich Cloud-Ready Solutions

Thurupathan Vijayakumar

Practical Azure Application Development Thurupathan Vijayakumar Colombo, Sri Lanka ISBN-13 (pbk): 978-1-4842-2816-6 DOI 10.1007/978-1-4842-2817-3

ISBN-13 (electronic): 978-1-4842-2817-3

Library of Congress Control Number: 2017943372 Copyright © 2017 by Thurupathan Vijayakumar This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Cover image designed by Freepik Managing Director: Welmoed Spahr Editorial Director: Todd Green Acquisitions Editor: Nikhil Karkal Development Editor: Laura Berendson Technical Reviewer: Pranab Majumdar Coordinating Editor: Prachi Mehta Copy Editor: Karen Jameson Compositor: SPi Global Indexer: SPi Global Artist: SPi Global Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. For information on translations, please e-mail [email protected], or visit http://www.apress.com/rights-permissions. Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web page at http://www.apress.com/bulk-sales. Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the book’s product page, located at www.apress.com/ 978-1-4842-2816-6. For more detailed information, please visit http://www.apress.com/ source-code. Printed on acid-free paper

This book is dedicated to my loving parents

Contents at a Glance About the Author���������������������������������������������������������������������������� xiii About the Technical Reviewer��������������������������������������������������������� xv Acknowledgments������������������������������������������������������������������������� xvii Introduction������������������������������������������������������������������������������������ xix ■Chapter ■ 1: Azure – A Solutions Development Platform������������������ 1 ■■Chapter 2: Beginning Application Development with Azure Web Apps, SQL Database, and Blob Storage���������������������� 11 ■■Chapter 3: DevOps with Visual Studio Team Services and Azure������������������������������������������������������������������������������������� 45 ■Chapter ■ 4: Azure Active Directory and Multitenancy������������������� 65 ■Chapter ■ 5: Getting Started with Azure NoSQL Services���������������� 97 ■Chapter ■ 6: Security and Data Protection������������������������������������ 131 ■Chapter ■ 7: Integrating Azure Search������������������������������������������ 157 ■Chapter ■ 8: Data Visualization with Power BI Embedded������������ 175 Index���������������������������������������������������������������������������������������������� 191

v

Contents About the Author���������������������������������������������������������������������������� xiii About the Technical Reviewer��������������������������������������������������������� xv Acknowledgments������������������������������������������������������������������������� xvii Introduction������������������������������������������������������������������������������������ xix ■Chapter ■ 1: Azure – A Solutions Development Platform������������������ 1 Let’s Define IaaS, PaaS, and SaaS����������������������������������������������������������� 1 Infrastructure as a Service (IaaS)����������������������������������������������������������������������������� 1 Platform as a Service (PaaS)������������������������������������������������������������������������������������ 2 Software as a Service (SaaS)����������������������������������������������������������������������������������� 2

PaaS Services of Azure��������������������������������������������������������������������������� 3 Azure Account and Subscriptions������������������������������������������������������������ 4 Azure Deployment Models����������������������������������������������������������������������� 5 Azure Resource Manager and Resource Groups������������������������������������� 6 Azure Regions����������������������������������������������������������������������������������������� 6 Introduction to Azure Portal��������������������������������������������������������������������� 6 Azure Compliances���������������������������������������������������������������������������������� 7 Introduction to DashDocs Application����������������������������������������������������� 8 DashDocs Application����������������������������������������������������������������������������������������������� 8

Summary������������������������������������������������������������������������������������������������� 9

vii

 ■ Contents

■■Chapter 2: Beginning Application Development with Azure Web Apps, SQL Database, and Blob Storage���������������������� 11 Beginning DashDocs Application Development������������������������������������� 11 Getting Started with Azure Web Apps���������������������������������������������������� 13 Choosing the Hosting Option���������������������������������������������������������������������������������� 13 Web Apps vs. Cloud Services vs. VMs�������������������������������������������������������������������� 14 Creating an Azure Web App������������������������������������������������������������������������������������ 14 Azure App Service Plan������������������������������������������������������������������������������������������� 16 Azure Web Apps Deployment Options��������������������������������������������������������������������� 17 Publishing the Application from Visual Studio�������������������������������������������������������� 18 Exploring the Publish Settings File������������������������������������������������������������������������� 19

Getting Started with Azure SQL Database��������������������������������������������� 20 Creating an Azure SQL Database���������������������������������������������������������������������������� 20 Accessing Azure SQL Database from SSMS����������������������������������������������������������� 23 Entity Framework Code-First with Azure SQL Database����������������������������������������� 25 Creating the Code-First Models������������������������������������������������������������������������������ 26

Getting Started with Azure Blob Storage����������������������������������������������� 30 Creating an Azure Blob Storage������������������������������������������������������������������������������ 31 Azure Blob Storage Replication������������������������������������������������������������������������������ 33 Azure Blob Storage Structure��������������������������������������������������������������������������������� 34 Accessing Azure Blob Storage from SDK���������������������������������������������������������������� 36

Finalizing the First Version of DashDocs Application���������������������������� 41 Summary����������������������������������������������������������������������������������������������� 43 ■■Chapter 3: DevOps with Visual Studio Team Services and Azure������������������������������������������������������������������������������������� 45 Getting Started with VSTS��������������������������������������������������������������������� 45 Setting Up a VSTS Account������������������������������������������������������������������������������������� 45 Creating a Git Repo and Pushing the Code to VSTS������������������������������������������������ 47 Creating Build Definition and Deployment to Azure Web Apps������������������������������� 50 viii

 ■ Contents

Enabling Application Monitoring Using Azure Application Insights������������������������������������������������������������������������������� 56 Automate Azure Environment Provisioning Using Azure Resource Manager (ARM) Templates���������������������������������������������������� 59 Handling Environment Settings in Web Apps���������������������������������������������������������� 63

Summary����������������������������������������������������������������������������������������������� 64 ■Chapter ■ 4: Azure Active Directory and Multitenancy������������������� 65 AAD and Azure Login Experience���������������������������������������������������������� 65 Microsoft Account Login����������������������������������������������������������������������������������������� 65 Creating an AAD User��������������������������������������������������������������������������������������������� 66 Inviting External Users to AAD�������������������������������������������������������������������������������� 69

Role Based Access Control (RBAC)�������������������������������������������������������� 72 Assigning Resources to the Users�������������������������������������������������������������������������� 72

Enabling Multitenancy with AAD����������������������������������������������������������� 73 Setting Up the AAD Application in the Portal���������������������������������������������������������� 73 AAD Authentication Flow and App Permissions������������������������������������������������������ 78 Configuring the MVC Application to Use AAD Authentication���������������������������������� 80

Summary����������������������������������������������������������������������������������������������� 95 ■Chapter ■ 5: Getting Started with Azure NoSQL Services���������������� 97 Azure Table Storage������������������������������������������������������������������������������ 97 Creating a Table Storage����������������������������������������������������������������������������������������� 98 Azure Table Storage Structure�������������������������������������������������������������������������������� 99 Programmatically Accessing Azure Table Storage������������������������������������������������ 100 Insert Data to Azure Table Storage Using Azure Storage SDK������������������������������ 102 Retrieve Data from Azure Table Storage Using Azure Storage SDK���������������������� 106

Azure Document DB���������������������������������������������������������������������������� 106 Azure Document DB Structure������������������������������������������������������������������������������ 107 Creating Azure Document DB������������������������������������������������������������������������������� 107

ix

 ■ Contents

Document DB Consistency Levels������������������������������������������������������������������������ 111 Programmatically Access Azure Document DB with SDK������������������������������������� 111 Install-Package Microsoft.Azure.DocumentDB����������������������������������������������������� 112

Redis��������������������������������������������������������������������������������������������������� 119 Setting Up Redis on Azure������������������������������������������������������������������������������������ 120 Accessing Redis Service on Azure through SDK�������������������������������������������������� 121 Monitoring Redis Using Azure Portal�������������������������������������������������������������������� 127

Summary��������������������������������������������������������������������������������������������� 130 ■Chapter ■ 6: Security and Data Protection������������������������������������ 131 Security Features of Azure SQL Database������������������������������������������� 131 Transparent Data Encryption (TDE)����������������������������������������������������������������������� 131 Dynamic Data Masking����������������������������������������������������������������������������������������� 133 Auditing and Threat Detection������������������������������������������������������������������������������ 134

Security Features of Azure Storage Services�������������������������������������� 136 Azure Key Vault����������������������������������������������������������������������������������� 137 Provisioning Azure Key Vault�������������������������������������������������������������������������������� 138 Generating a Key in the Azure Key Vault��������������������������������������������������������������� 140 Azure Storage Client Side Encryption with Azure Key Vault – Settings���������������� 142 Azure Storage Client Side Encryption with Azure Key Vault – Development�������� 147

Summary��������������������������������������������������������������������������������������������� 155 ■Chapter ■ 7: Integrating Azure Search������������������������������������������ 157 Azure Search Components������������������������������������������������������������������ 157 Provisioning an Azure Search Service������������������������������������������������������������������ 158 Creating a Search Index and Import Data������������������������������������������������������������� 159

Testing Azure Search via Portal����������������������������������������������������������� 166 Integrating Azure Search to the Application via SDK��������������������������� 168 Summary��������������������������������������������������������������������������������������������� 173

x

 ■ Contents

■Chapter ■ 8: Data Visualization with Power BI Embedded������������ 175 Creating Power BI Reports Using Power BI Desktop��������������������������� 175 Set the Application Models for Reporting Purposes��������������������������������������������� 175 Creating the Power BI Report������������������������������������������������������������������������������� 177

Publish Power BI Files to Azure Power BI Embedded�������������������������� 180 Creating Power BI Embedded Service Using the Portal���������������������������������������� 181 Provision the Power BI Embedded Workspace and Publish Reports�������������������� 182

Embed Power BI Reports in the Web Application�������������������������������� 186 Summary��������������������������������������������������������������������������������������������� 190 Index���������������������������������������������������������������������������������������������� 191

xi

About the Author Thurupathan Vijayakumar (Thuru) is an associate solutions architect at Tiqri (www.tiqri.com) and a Microsoft Azure MVP. Thuru has been involved in the design and development of various software solutions for many enterprises and startups. Thuru is a versatile speaker and a known blogger. He specializes in software design, business intelligence, the security development life cycle, and data intelligence services. He lives in Colombo and enjoys traveling and eating. Blog: www.thuru.net, Twitter: @thurutweets.

xiii

About the Technical Reviewer Pranab Majumdar is currently working as an Escalation Engineer for the Microsoft Azure SQL Database and Azure SQL Datawarehouse. He will be moving as an Embedded Escalation Engineer working very closely and partnering with the Engineering team. Prior to getting aligned to the Cloud side of the Business, he was an Escalation Engineer with the SQL Server team in CSS/GBS where he worked with the Product Team to fix bugs within the SQL Server Product thereby making SQL a better and Preferred RDBMS. He has been working with Microsoft for close to 12 years now with his specialization in SQL Server Engine, Performance, High Availability and disaster recovery. He has worked with a lot of large corporates with huge and very large and complex SQL deployments.. Apart from SQL he has also been working with operational Insight formerly known as System Centre Advisor, migrating and helping create new set of rules and validation process. He holds a number of Microsoft certifications like MCAD, MCSD, MCDBA, MSCE, MCTS, MCITP and MCT since 2005. The latest one being Azure certified. He likes to be connected to the customers and he has been a speaker in TechEd, GIDs, SQL Saturday, SQL Talks, and other Community UG Events.

xv

Acknowledgments Practical Azure Application Development: A Step-by-Step Approach to Build Feature-Rich Cloud-Ready Solutions is a knowledge source that explains different Azure services and how to use them in building enterprise-level software solutions. Most of the content of this book has been acquired from knowledge and experience gathered during my tenure at Tiqri Corp, and I am grateful for the company and my team. I am thankful to my colleagues who gave support and courage in writing this book and guiding me towards the completion; my special thanks goes to Ms. Thushara Wijewardena, CPO of Tiqri, who motivated me continuously from the beginning to the completion of this book. I wish to thank Laura Berendson, Nikhil Karkal, and Prachi Mehta from Apress who assisted me in many ways, in completing this book.

xvii

Introduction The terms Cloud computing or Microsoft Azure are not new to the industry. Azure has been one of the leading and well-proven cloud platforms, which creates a growing demand for the Azure skills in the industry. Although Azure has many knowledge sources, they all lack a fundamental aspect of creating solutions using Azure services. Those knowledge sources target the specific service offering of the Azure and shows what it is and how it works, but in reality we use many different cloud services as a combined package to deliver the solutions. Practical Azure Application Development: A Step-by-Step Approach to Build Feature-Rich Cloud-Ready Solutions – fills the skill gap and targets how a real-world problem can be modeled on top of different Azure services and how those services can be leveraged in cutting down development effort while considering the right options for the problem in hand. This books covers 13 different Azure services that are very common in enterprise application development scenarios, including the basic DevOps cycle. The book begins by detailing how to obtain an Azure account to using different services in different stages of the application development with the help of a sample multitenant-based document management solution. The book has the accompanying code for each chapter that helps the readers to try out what they learn. This solution-based unique approach makes this book a special guide in Azure application development space and an interesting read.

xix