O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Serverless computing in Azure with .NET

Book Description

Harness the power of the Cloud, leveraging the speed and scale of Azure Serverless computing

About This Book

  • Take advantage of the agility, scale, and cost-effectiveness of the cloud using Azure Serverless compute
  • Build scalable, reliable, and cost-effecient applications with Serverless architecture and .NET
  • Learn to use Azure functions to their fullest potential in .NET

Who This Book Is For

This book is for .NET developers who would like to learn about serverless architecture. Basic C# programming knowledge is assumed.

What You Will Learn

  • Understand the best practices of Serverless architecture
  • Learn how how to deploy a Text Sentiment Evaluation application in an Azure Serverless environment
  • Implement security, identity, and access control
  • Take advantage of the speed of deployment in the cloud
  • Configure application health monitoring, logging, and alerts
  • Design your application to ensure cost effectiveness, high availability, and scale

In Detail

Serverless architecture allows you to build and run applications and services without having to manage the infrastructure. Many companies have started adopting serverless architecture for their applications to save cost and improve scalability.

This book will be your companion in designing Serverless architecture for your applications using the .NET runtime, with Microsoft Azure as the cloud service provider. You will begin by understanding the concepts of Serverless architecture, its advantages and disadvantages. You will then set up the Azure environment and build a basic application using a sample text sentiment evaluation function. From here, you will be shown how to run services in a Serverless environment. We will cover the integration with other Azure and 3rd party services such as Azure Service Bus, as well as configuring dependencies on NuGet libraries, among other topics. After this, you will learn about debugging and testing your Azure functions, and then automating deployment from source control. Securing your application and monitoring its health will follow from there, and then in the final part of the book, you will learn how to Design for High Availability, Disaster Recovery and Scale, as well as how to take advantage of the cloud pay-as-you-go model to design cost-effective services. We will finish off with explaining how azure functions scale up against AWS Lambda, Azure Web Jobs, and Azure Batch compare to other types of compute-on-demand services.

Whether you’ve been working with Azure for a while, or you’re just getting started, by the end of the book you will have all the information you need to set up and deploy applications to the Azure Serverless Computing environment.

Style and approach

This step-by-step guide shows you the concepts and features of Serverless architecture in Azure with .NET.

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

Table of Contents

  1. Preface
    1. What this book covers
    2. What you need for this book
    3. Who this book is for
    4. Conventions
    5. Reader feedback
    6. Customer support
      1. Downloading the example code
      2. Errata
      3. Piracy
      4. Questions
  2. Understanding Serverless Architecture
    1. What is serverless?
    2. Azure serverless
    3. Architecture
      1. Inherent features
        1. Asynchronous
        2. Stateless
        3. Idempotent and defensive
        4. Execution restrictions
          1. Limited execution time
          2. Startup latency
      2. Advantages of serverless computing
        1. Scalability
        2. Pay-As-You-Go
        3. Reduced operational costs
        4. Speed of deployment
        5. Independent technology stack and updates
        6. Integration with the cloud provider
        7. Open source
      3. Disadvantages of serverless computing
        1. Distributed system complexity
        2. Potential load on downstream components
        3. Potential for repetitive code
        4. Different operations
          1. Security and monitoring
          2. Testing
        5. Vendor control
        6. Vendor lock-in
        7. Multitenancy
      4. Vendor-specific limitations
    4. Applications
    5. Summary
  3. Getting Started with the Azure Environment
    1. Microsoft Azure Cloud
      1. Azure account
      2. Azure subscription
        1. Subscription constraints
        2. Creating a subscription
      3. Azure Management APIs
        1. API access
        2. The Azure Resource Manager API
          1. Resource groups
          2. Azure Resource Manager templates
      4. Azure Management Portal
    2. Azure serverless computing
      1. Hosting Plan
      2. Function App
      3. Azure Function
    3. Deploying a function
      1. Creating an Azure serverless environment
        1. The App name parameter
        2. The Subscription parameter
        3. The Resource Group parameter
        4. The Hosting Plan parameter
        5. The Location parameter
        6. The Storage parameter
        7. The Automation options link
        8. Deploying the application
      2. Functions Portal
      3. Deploying Azure Functions online
        1. Function files
          1. The function.json file
          2. The run.csx file
        2. HTTP endpoint
      4. Exploring the Functions Portal
        1. The Test pane
        2. Function logs
        3. Error output
      5. Function App settings
        1. Application Settings
        2. Daily Usage Quota
        3. The runtime version
        4. The Function App edit mode
        5. Host keys
        6. Slots
        7. Proxies
      6. The Platform features pane
        1. App Service Editor
        2. Dev Console
        3. Resource Explorer
    4. Clean up Azure resources
      1. Deleting a function
      2. Deleting the Function App
      3. Deleting the resource group
      4. Exploring further options
    5. Summary
  4. Setting Up the Development Environment
    1. Configuring the development environment
      1. Downloading and installing Visual Studio
      2. Creating the project
      3. Function App Configuration Files
        1. The local.settings.json file
      4. The host.json file
    2. Creating the function
      1. Running the function locally
    3. Deploying the application to Azure
      1. Modifying the text scoring function
        1. Updating the function code
        2. Republishing the function to Azure
    4. Storing the results
      1. Setting up the SQL PaaS database in Azure
        1. Creating the SQL Server
      2. Managing the SQL database from Visual Studio
      3. Creating the DocumentTextScore table
      4. Integrating the ScoreText function with the SQL database
      5. Modifying the function to store results in SQL
    5. Setting up a web dashboard for scoring results
      1. Connecting the ASP.Net Core Web Application to the database
        1. Installing Entity Framework dependencies
        2. Get the SQL Azure connection string
        3. Updating the generated database context
        4. Dependency injection
        5. Creating the web UI
          1. Creating the MVC controller
          2. Creating the MVC view
        6. Changing the application home page
      2. Publishing to Azure
      3. Tying it all together
    6. Summary
  5. Configuring Endpoints, Triggers, Bindings, and Scheduling
    1. Triggers and bindings
      1. Triggers
      2. Binding
        1. Trigger binding
        2. Input binding
        3. Output binding
      3. Advanced bindings
    2. Endpoints
      1. Custom routes
      2. Allowed methods
      3. API definition
      4. Proxies
      5. Securing the endpoints
    3. Blob Storage trigger
      1. Creating a storage account for document upload
      2. Getting the storage connection string
      3. Creating a Blob trigger function
      4. Function code
        1. Triggering the function
        2. Updating the function to process text
    4. Timer trigger
      1. CRON expression
      2. Implementing the average result function
        1. Defining the SQL table binding
        2. Finding an existing entity
      3. Full Function Code
    5. Summary
  6. Integrations and Dependencies
    1. Processing a Twitter feed
      1. Creating a WebHook Trigger function
      2. Creating the Logic App to search Twitter
    2. Sharing code between functions
    3. Integrating with a Service Bus queue
      1. Email processing using Service Bus
      2. Creating a Service Bus queue
        1. Configuring the access permissions
        2. Listen Access Policy for the function
        3. Send Access Policy for the Logic App
        4. Creating the function
      3. Other Service Bus configuration options
        1. Sending email messages to Service Bus Queues
        2. Testing the Service Bus flow
    4. .NET dependency
    5. Adding NuGet libraries
    6. Summary
  7. Integrating Azure Functions with Cognitive Services API
    1. Using Microsoft Cognitive Services APIs to analyze text
      1. Creating a Cognitive API account
      2. Text sentiment API usage
    2. The text sentiment analytics API call implementation
      1. Constructing the payload
      2. Calculating the overall score
      3. Using Sentiment Analysis in Azure Functions
        1. A short text analysis example
        2. A long text analysis example
    3. Storing the function results
      1. Storing tweet score results using the shared code
        1. Creating the TweetTextScore table
        2. Updating the ScoreTweet function
      2. Reflecting the new results in the Web dashboard
        1. Updating the model from database
        2. Updating controllers and views
    4. Summary
  8. Debugging Your Azure Functions
    1. Software debugging
    2. Logging events
      1. Logging best practices
        1. Logging adequately
        2. Logging with context
        3. Logging in a readable format
        4. Logging at the proper level
        5. Logging during normal operation
    3. Debugging the functions locally
      1. Debugging functions with Visual Studio
      2. Triggering the functions
        1. HTTP-triggered function
        2. Triggering functions using Functions Core tools
        3. Blob Storage triggered function
      3. Triggering a function using custom code
        1. Triggering a function using functions
          1. Triggering the Service Bus queue function locally
    4. Handling errors
    5. Remote debugging in the cloud
    6. Summary
  9. Testing Your Azure Functions
    1. The importance of testing
    2. Software testing
      1. Software assessment perspectives
        1. Code correctness
          1. Unit testing
          2. Integration testing
          3. System testing
        2. Performance
          1. Performance testing
          2. Load testing
        3. Usability
    3. Testing the functions
      1. Unit testing
        1. Unit testing approach
          1. Naming convention
          2. Unit test best practices
          3. What to cover
          4. Mocking frameworks
          5. Dependency injection
        2. Creating a test project
        3. Creating a unit test
          1. The ProcessQueue function - input string, and logged output
        4. Getting more granular
          1. Asynchronous tests
        5. Unit test examples
          1. Unit test examples
          2. The EvaluateText class - API failure and method failure
      2. Integration testing
        1. The ScoreTweet function - updating an entity
    4. Performance testing
      1. Load testing
    5. Summary
  10. Configuring Continuous Delivery
    1. Version Control System
      1. Centralized VCS
      2. Distributed VCS
      3. Common practices
        1. Committing best practices
        2. Database versioning
    2. Continuous Integration and delivery
    3. Version control for functions
      1. Configuring VSTS
      2. Configuring the repository
      3. Linking the Azure subscription to VSTS
    4. Continuous delivery for functions
      1. Deployment slots
      2. Configuring the VSTS build process
        1. Configuring the NuGet restore task
        2. E-mail notifications
      3. Configuring Release
    5. Load testing with VSTS
    6. Automating Function App deployment
    7. Summary
  11. Securing Your Application
    1. Securing the application
    2. Physical security
    3. Host infrastructure
    4. Networking security
      1. Integrating functions with a private network
      2. Networking concepts
      3. Azure App Service
        1. VNet integration
        2. Hybrid connections
      4. App Service Environment
        1. ASE deployment modes
        2. Public App Service Environment
          1. Adding a Network Security Group
        3. Adding an NVA
        4. Private App Service Environment
    5. Application-level security
      1. Authorization and authentication
        1. Anonymous mode
        2. API key authorization
          1. HTTP trigger
          2. Webhook trigger functions
        3. User-based authentication
          1. Configuring Azure Active Directory
          2. Third-party identity providers
      2. Code quality
      3. Managing keys and secrets
      4. Data encryption at rest
      5. Data encryption in transit
        1. Configuring a custom domain
        2. Configuring SSL
      6. Configuring CORS
    6. Administrative access
      1. Role-based access control
      2. Resource locks
    7. Summary
  12. Monitoring Your Application
    1. Application performance management
      1. Detect
      2. Diagnose
      3. Measuring and learning
    2. Monitoring tools
      1. Collecting logs
      2. Creating charts
      3. Setting up alerts
        1. Avoiding alert fatigue
        2. Alerting on actionable items
    3. Functions monitoring tools
    4. Functions Monitor tab
    5. Application Insights
    6. Monitoring functions with Application Insights
      1. Setting up local configuration
      2. Staging slot reporting
      3. Application Insights dashboards
      4. Live Stream
      5. Metrics dashboards
        1. Performance dashboard
          1. Dashboard customization
        2. Servers dashboard
        3. Failures dashboard
        4. Metrics Explorer
        5. Custom telemetry
        6. Analytics view
      6. Setting up alerts
        1. Smart Detection
    7. Summary
  13. Designing for High Availability, Disaster Recovery, and Scale
    1. High Availability
      1. Service downtime
      2. Azure services SLAs
        1. What is covered by the SLA
        2. What is not covered by the SLA
      3. Fault tolerance
        1. Elimination of single points of failure
        2. Transient fault handling
          1. Setting timeouts
          2. The Retry pattern
          3. The Circuit Breaker pattern
          4. Message Queuing
          5. The Retry pattern in Azure Functions
          6. The Retry logic in Logic Apps
        3. Fault containment
        4. Fault detection
      4. Prevention of human errors
    2. Disaster Recovery
      1. What is a disaster?
      2. Disaster Recovery planning in Azure
      3. DR site type
      4. Implementing a hot DR site
        1. DR in Functions
        2. Web Apps
        3. Logic Apps
        4. Azure Service Bus
        5. Azure Storage
        6. Azure SQL Database
          1. The Text Analytics API
    3. Scaling the application
      1. Scaling serverless compute
        1. Consumption plan
        2. App Service plan
        3. Scaling other application components
          1. Web Apps
          2. Azure SQL Database
          3. Azure Service Bus
          4. Azure Storage
          5. Logic Apps
          6. Text Analytics API
      2. Load testing
    4. Summary
  14. Designing Cost-Effective Services
    1. Pay for what you use
    2. Azure Functions pricing
      1. Consumption plan
        1. The Consumption plan pricing based on load
      2. App Service plan
        1. The App Service plan pricing based on load
    3. The overall application cost
      1. Web Apps
        1. Web App pricing based on load
      2. Azure SQL Database
        1. Azure SQL Database pricing based on load
      3. Azure Blob Storage
        1. Azure Blob Storage pricing based on load
      4. Azure Logic Apps
        1. Azure Logic App pricing based on load
      5. Azure Service Bus
        1. Azure Service Bus pricing based on load
      6. The Text Analytics API
        1. Text Analytics API pricing based on load
      7. Network bandwidth
      8. Application Insights
        1. Application Insights pricing based on load
      9. Visual Studio Team Services
    4. Calculating the overall applications costs
    5. Summary
  15. C# Script-Based Functions
    1. C# script-based functions
    2. Using NuGet libraries
      1. Option 1 - the #r directive
      2. Option 2 - the project.json file
    3. Sharing code between functions
    4. Summary
  16. Azure Compute On-Demand Options
    1. Compute on-demand
    2. Azure WebJobs
    3. Azure Logic Apps
    4. Azure Batch
    5. Azure PaaS Cloud Services
    6. Summary