Building Serverless Apps with Azure Functions and Cosmos DB
US$ 19.95
The publisher has enabled DRM protection, which means that you need to use the BookFusion iOS, Android or Web app to read this eBook. This eBook cannot be used outside of the BookFusion platform.
Description
Contents
Reviews
Language
English
ISBN
9789389328387
Cover Page
Title Page
Copyright Page
Dedication Page
About the Author
About the Reviewer
Preface
Errata
Table of Contents
1. Beginning Azure Function Apps
Introduction
Prerequisites
Structure
Objective
Azure serverless architecture
What is Azure serverless architecture?
Why serverless architecture
Real-world case studies of serverless applications
A single-page web application
Web application backend
Mobile application backend
IoT backend
Real-time file processing
Real-time stream processing
Automating tasks
SaaS integration
Azure Serverless platform
Azure functions
Logic Apps
Event Grid
Before it is serverless
Applications in on-prem
IaaS
PaaS
Serverless applications
First steps with Azure function
What is an Azure function?
Features of Azure functions
Function development is easy
You have a variety of languages to select from
Set up continuous integration and deployment
You can develop your functions from a Linux environment
Pay for what you use
Use your dependencies
Integrate with other Azure services
Integrate functions with third-party services
Security for your functions
Open source function runtime
Service integrations
Azure Cosmos DB
Azure Event Hub
Azure Event Grid
Azure Notification Hub
Azure Service Bus
Azure Storage
Azure Logic Apps
Azure SignalR
Microsoft Graph
Power BI
Twilio API
SendGrid API
Language support for functions
C#
F#
JavaScript
Java
Python
TypeScript
PHP
Batch
Bash
PowerShell
Triggers and Bindings
Triggers
Bindings
Type of applications using Azure functions
Serverless web applications
Serverless mobile backend
Timer-based processing
Real-time file processing
Real-time stream processing
Real-time bot processing
Pricing in Azure functions
Consumption plan
Function scaling in consumption plan
Billing in consumption plan
App service plan
Function scaling in app service plan
Billing in app service plan
When to use app service plan
Conclusion
Questions
2. Your First Azure Function App
Introduction
Prerequisites
Structure
Objective
Function in the portal
Http trigger
What is an Http trigger?
Http trigger runtime
Supported languages
Http trigger attributes and configurations
Creating our first function in the Azure portal
Blob trigger
What is a blob trigger?
Blob trigger runtime
Supported languages
Blob trigger attributes and configurations
Creating a blob trigger from the Azure portal
A function from an IDE
Timer trigger in Visual Studio
What is a timer trigger?
Timer trigger runtime
Supported languages
Timer trigger attributes and configurations
Creating a timer trigger in Visual Studio
Deploying timer trigger to Azure
Queue trigger in Visual Studio Code
What is a queue trigger?
Queue Trigger runtime
Supported languages
Queue trigger attributes and configurations
Creating a queue trigger in Visual Studio Code
Deploy queue trigger to Azure
Source Codes
Conclusion
Questions
3. Let’s Get Started with Cosmos DB
Prerequisites
Structure
Objective
Azure Cosmos DB
NoSQL databases
Distributed
Scalable
Open-source
Schema free
Easy replication support
Simple API
Support for a vast amount of data
No conversion from database schema to view models
Why NoSQL databases
Improves programmer productivity
Improves performance in reads
Open-source
ACID transactions
Polyglot persistence
Scalable
Sharding
Myths in NoSQL databases
NoSQL can replace SQL
NoSQL is better or worse than SQL
Language or framework determines the database
NoSQL is not secure
NoSQL is not reliable
NoSQL is not scalable
NoSQL is not usable
NoSQL is not ready for severe applications
When to select NoSQL databases
Cosmos DB: multi-model and API support
Cosmos DB - Multiple model databases
Documents
Key-value pairs
Column family
Graph databases
Cosmos DB - multi API support
SQL API
Mongo API
Cassandra API
Table API
Gremlin API
Features in Cosmos DB
Data partitioning and global distribution
Scale throughout and storage
Service Level Agreements
Cosmos DB consistency levels
Data consistency and availability
Data consistency and response time
Database schema and index management
Hash index
Range index
Request units and pricing
Running queries on Cosmos DB
Conclusion
Questions
4. Structure Your Data in Cosmos DB
Introduction
Prerequisites
Structure
Objective
Structuring documents
Are you non-relational?
Creating documents
Modeling data in a relational database
Modeling data in a document database
Creating a Cosmos DB account
Relationships - embed versus reference
Embed relationship
Reference relationship
Scaling the Cosmos DB
Settings in Cosmos DB collection
Conflict resolution
Partition key
Database schema and indexing
Stored procedures, UDF, and Triggers in Cosmos DB
Stored procedure
User-defined function
Triggers
Querying Cosmos DB
Select all the products in the catalog
Select a specific product from id
Select a specific product from the price
Select products from stock location
Select all the invoices belonging to a specific product
Conclusion
Questions
5. Your First Cosmos DB
Introduction
Prerequisites
Structure
Objective
A document DB from SQL API
Migrating an on-prem MongoDB to Cosmos MongoDB
Create Cosmos DB account
Migrate a MongoDB to a Cosmos DB
Create database migration service in Azure
Create database migration project in Azure
A table API app with Cosmos DB
Create Cosmos DB account
Add table to a database
Add entities to a table
Querying on a table
Read data by passing partition key - get all the long sleeves men’s shirts
Read data by passing partition key and row key - get all the long sleeves, large size men’s shirts
Read data by passing partition key and another column - get all the long sleeves and white color men’s shirts
Read data by passing a column - get all the shirts for price 15 USD
Read-only selected columns - get long sleeves, white color men’s shirts price, and available sizes
Read data with operators - get shirts price more significant than 15 USD or color white
Read boolean values - get shirts available in the stock and red color
Scaling Cosmos DB tables
Why Azure Cosmos DB Table API
Global distribution
High availability
Dedicated throughput in all the Azure regions
Different levels of SLAs
Single-digit millisecond latency
Indexing on all properties
Fast data retrieval
Five different levels of data consistency
Pricing based on the throughput
99.99% of read-write availability
A graph database using Gremlin API
Create Cosmos DB account
Create a database in the Cosmos DB account
Create a graph in the database
Querying the graph database
Simple queries on graph database
Traversals on graph database
Update queries on graph
Delete queries on graph
Run an SQL query on the graph
Scaling graph databases
Conclusion
Questions
6. Serverless Design Patterns
Introduction
Prerequisites
Structure
Objective
Durable functions
What is a durable function?
When should we use durable functions?
Durable function - Supported languages
Durable function - Pricing
Durable functions and Logic Apps
Logic Apps
Durable functions versus Logic Apps
Durable function types
Activity functions
Orchestrator functions
Entity functions
Client functions
Durable function patterns
Real-world example - Durable function
Create a durable function
Change the durable function
Publish to Azure
Function chaining
What is function chaining?
Real-world example - Function chaining
Apply function chaining pattern
Publish to Azure
Fan-out/Fan-in
What is fan-out/fan-in?
Real-world example - Fan-out/Fan-in
Apply Fan-out/Fan-in pattern
Test the function in Azure
Async function calls
What is Async function calls?
Real-world example - Async function calls
Apply async Http API pattern
Test the function in the cloud
Human interaction in a function app
How to manage human interaction in a function
Real-world example - Human interaction
Get human input to an Azure function
Publish the function to cloud
Aggregator
What is an aggregator function?
Real-world example - Aggregator
Implement the aggregator pattern with entity function
Publish the function to cloud
Source Codes
Conclusion
Questions
7. Performance and Scalability of a Function App
Introduction
Prerequisites
Structure
Objective
Optimize performance in a function app
Avoid long-running functions
Manage cross-functional communication wisely
Use durable functions to create a stateful environment
Implement defensive functions
Avoid function cold start
Authorize your function app
Secure functions using Azure Active Directory
Share the code across functions using class libraries
Strongly typed classes in functions
Share and manage external connections
Separate test and production code
Don’t use verbose logging in production
Receive messages in batches
Scaling in a function
Hosting plans
App service plan
Consumption plan
Premium plan
Storage account
Conclusion
Questions
8. Geo-Distribution in a Function App
Introduction
Prerequisites
Structure
Objective
High availability in function apps
Achieving high availability in a function app
Active/Active function deployment
Active/Passive function deployment
Achieving high availability in storage
Sharing the central region storage in both function apps
Using regional storage for each function app
Use geo-redundant storage in both function apps
Disaster recovery options for bindings
Azure SQL database
Azure Cosmos DB
Azure storage
Conclusion
Questions
9. Error Handling and Testing
Introduction
Prerequisites
Structure
Objective
Error handling in an Azure function
Write logs
Log levels
Log extension methods
Structured error handling
Error codes
Enable application insights
Design the functions for exact inputs
Write retry policies
Error handling in durable functions
Structured error handling
Retry policies
Durable timer
Unhandled exceptions
Writing unit tests in a function
Function unit tests
Unit tests in C#
xUnit
Create an http trigger function in c#
Create a xUnit test project
Run tests in Visual Studio
Unit tests in JavaScript
Jest
Create an http trigger function in JavaScript
Create test methods
Run tests in Visual Studio Code
Source codes
Conclusion
Questions
10. Secure Your Function App
Introduction
Prerequisites
Structure
Objective
Authenticate using Azure Active Directory
Create a function app
Create a new Azure Active Directory
Configure the Azure Active Directory
Attach Azure Active Directory in the function app
Authenticate using Google
Create a Google API application
Attach Google authentication in the function app
Function App IP restrictions
Manage secrets with Azure Key Vault
Create a Key Vault
Manage secrets in Key Vault
View the secret stored in Key Vault
Conclusion
Questions
11. Deployments in a Function App
Introduction
Prerequisites
Structure
Objective
Deploying to Azure
Deploying your function using Azure CLI
Continuous deployment to Azure function
Configure CI/CD pipeline in the function app
Test the CI/CD workflow
Source codes
Conclusion
Questions
12. Monitor and Troubleshoot Function Apps
Introduction
Prerequisites
Structure
Objective
Monitor a function app
Real-time application logs
Diagnostics in a function app
Diagnose and solve the problems
Explore Application Insights
Enable Application Insights to an existing function app
View telemetry data in the monitor tab
Query telemetry data
View telemetry data in Application Insights
Live metric stream in Application Insights
Benefits of Azure Application Insights
Conclusion
Questions
13. Azure Functions with Cosmos DB Table API
Introduction
Prerequisites
Structure
Objective
Case study - Process an excel file using Azure function and store data in table storage in Cosmos DB Table API
The structure of the CSV file
Run the solution
Your first .NET Core 3 function in Cosmos DB Table API
Read the CSV file
Create table in Cosmos DB
Create a row in Cosmos DB Table API
Retrieve data from keys in Cosmos DB Table API
Settings file
Your first function using Typescript on Cosmos DB Table API
Create a table service in Cosmos DB account
Create a table in Cosmos DB account
Store course data
Read the CSV file
Create a row in Cosmos DB Table API
Retrieve data from keys in Cosmos DB Table API
Settings file
Required packages
Your first function using Python in Cosmos DB Table API
Create a table service in Cosmos DB account
Create a table in Cosmos DB account
Courses class to store data
Read the CSV file
Create a row in Cosmos DB Table API
Configurations in the code
Requirements to build the solution
Source codes
Conclusion
Questions
14. Azure Functions with Cosmos DB SQL API
Introduction
Prerequisites
Structure
Objective
Case study - Process outlook emails using Graph API and store them in a Cosmos DB (SQL API) using an HTTP trigger function
Run the solution
.NET Core 3 function in Cosmos DB SQL API
Explore MS Graph subscription API
What is Microsoft Graph API?
What is Subscription API?
Read emails using MS Graph API
Retrieve the email notification
Process email notification by calling mail API
Create a Cosmos DB client
Create a database
Create a container
Create items
Settings file
Required packages
TypeScript function on Cosmos DB SQL API
Retrieve the emails from Graph API
Save emails to Cosmos DB
Settings file
Required packages
Your first function using Python in Cosmos DB SQL API
Read emails from Graph API
Create a Cosmos DB client
Find databases in the Cosmos account
Create a database in the Cosmos account
Create a container in the Cosmos DB
Create documents in the Cosmos DB
Configurations file
Required packages
Source codes
Conclusion
Questions
15. Cosmos DB Trigger in Azure Function
Introduction
Prerequisites
Structure
Objective
Case study - Cosmos DB trigger to track document changes in the database
Run the solution
Cosmos DB trigger written in .NET Core
Cosmos DB trigger to track document changes
Send SMS notifications using an SMS API
Settings file
Required packages
Cosmos DB trigger written in TypeScript
Cosmos DB trigger to track document changes
Send SMS notifications using a SMS API
Settings file
Input/Output function bindings
Required packages
Cosmos DB trigger written in Python
Cosmos DB trigger to track document changes
Send SMS notifications using an SMS API
Configurations in the code file
Requirements to build the solution
Source codes
Conclusion
Questions
16. Azure Functions with Cosmos DB Gremlin API
Introduction
Prerequisites
Structure
Objective
Case study - Create a social network and relationships using Gremlin API on Cosmos DB and Azure function
Run the solution
Host your first graph data structure in Cosmos DB and process it using Azure function
Queue trigger to track new items
Create graph nodes
Create a graph client
Create new vertices
Create edges between vertices
Execute Gremlin query
Settings file
Required packages
Create a TypeScript function to process graph data in Cosmos DB
Queue trigger to track new items
Create graph nodes
Create a graph client
Create new vertices
Create edges between vertices
Settings file
Required packages
Create a Python program to process graph data in Cosmos DB using Azure function
Queue trigger to track new items
Create graph nodes
Create graph client
Create new vertices
Create edges between vertices
Requirements to the solution
Source codes
Conclusion
Questions
Index
Loading...