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 George Acquisition Editor: Shrilekha Inani Content Development Editor: Deepti Thore, Dattatraya More Technical Editor: Sayali Thanekar Copy Editor: Safis Editing Project Coordinator: Jagdish Prabhu Proofreader: Safis Editing Indexer: Rekha Nair Graphics: Jisha Chirayil Production 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 Preface 1 Chapter 1: Azure App Service 7 Technical requirements 7 Creating and deploying Azure App Service 8 Creating Azure App Service using the Azure Portal 8 Selecting Azure Web App from available services 8 Configuring an Azure web app 10 Creating an App Service Plan 11 Creating an Azure App Service using Visual Studio 15 Deploying Azure App Service using FTP 22 Deploying Azure App Service with user-level credentials 22 Deploying Azure App Service using app-level credentials 27 Downloading app-level credentials from the Azure Portal 28 Configuring WebDeploy in Visual Studio 29 Creating Azure App Services using Visual Studio Code 30 Working with different operating systems and platforms 33 Selecting an operating system 34 Selecting different platforms 35 Different App Service Plans and features 37 Dev/Test App Service Plans 38 Production App Service Plans 39 Isolated App Service Plans 40 Securing App Services using different security providers 41 Configuring authentication/authorization in the Azure Portal 41 Using Azure Active Directory to secure App Services 42 Using other authentication providers 46 Diagnostics and monitoring of App Services 46 The Overview blade 47 Metrics 47 Monitoring 48 Summary 49 Questions 49 Further reading 50 Chapter 2: Azure WebJobs 51 Technical requirements 51 Creating WebJobs 51 Creating and deploying WebJobs in Azure Portal 52 Creating an application in Visual Studio 52 Deploying a WebJob in the Azure Portal 53 Table of Contents Deploying WebJobs from Visual Studio 57 Working with the WebJobs SDK 60 Calling a job manually 63 Automatic triggers in WebJobs 64 Publish a job 66 Azure WebJobs limitations 67 Using different file types for WebJobs 68 Creating and deploying a Node.js application as a WebJob 68 Deploying a Node.js Azure WebJob from Visual Studio Code 69 Summary 71 Questions 71 Further reading 71 Chapter 3: Deploying Web Applications as Containers 72 Technical requirements 72 Working with AKS 73 Preparing an application 73 Container Registry and Kubernetes clusters 75 Pushing a Docker image to Azure Container Registry 76 Creating a Kubernetes cluster using AKS 79 Running, scaling, and updating an application in AKS 81 Solving problems with authentication 83 Scaling a cluster 85 Updating an application 85 Azure Container Instances 86 Creating and deploying an application and container 86 Pushing an image to Azure Container Registry 88 Deploying an application to ACI 88 Web App for Containers 91 Creating a web app hosted in a container 91 Deploying a custom application 95 Summary 97 Questions 98 Further reading 98 Chapter 4: Distributed Applications and Microservices with Service Fabric 99 Technical requirements 100 Understanding microservices 100 Monolith versus microservices 100 Microservice approach 101 Using different languages and frameworks 101 Scaling and updating services individually 102 Using well-designed interfaces and protocols 103 Dealing with state 103 Diagnosing and monitoring microservices 104 Containers, services, and actors in SF 105 [ ii ] Table of Contents Containers 105 Creating a cluster 105 Deploying a container 109 Packaging a service 111 Reliable services 112 Creating a SF application 112 Deploying an application to the cloud 117 Reliable actors 122 Creating a project with actors 123 Creating an actor's client 126 Communication between services 127 Creating a communication channel 128 Clusters in SF 131 Cluster security 132 Node-to-node security 132 Client-to-node security 133 Scaling 134 Scaling a cluster up or down 134 Monitoring and diagnostics 135 Application monitoring 135 Cluster monitoring 136 Health monitoring 136 Summary 137 Questions 138 Further reading 138 Chapter 5: Using Azure Search 139 Technical requirements 139 Creating an Azure Search service 139 Using Azure Portal 140 Full-text search in Azure Search 144 Sending a request 144 Linguistic analysis in full-text search 148 Analyzers in Azure Search 148 Analyzer selection 151 Indexing in Azure Search 152 Importing more data 152 Push model 152 Pull model 154 Cognitive search – adding AI to the indexing workload 155 Configuring Cognitive Search 156 Summary 158 Questions 158 Further reading 159 Chapter 6: Mobile Notifications with Notification Hub 160 [ iii ]