Hands-On Serverless Computing - Kuldeep Chowhan - E-Book

Hands-On Serverless Computing E-Book

Kuldeep Chowhan

0,0
40,81 €

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

Mehr erfahren.
Beschreibung

Deploy functions efficiently using different cloud-based serverless offerings




Key Features



  • Understand the concept of Function-as-a-Service


  • Implement Serverless solutions using AWS Lambda, Azure Functions and Google Cloud Functions


  • Practical approach towards choosing the best tool for your serverless environment





Book Description



Serverless applications and architectures are gaining momentum and are increasingly being used by companies of all sizes. Serverless software takes care of many problems that developers face when running systems and servers, such as fault tolerance, centralized logging, horizontal scalability, and deployments.






You will learn how to harness serverless technology to rapidly reduce production time and minimize your costs, while still having the freedom to customize your code, without hindering functionality. Upon finishing the book, you will have the knowledge and resources to build your own serverless application hosted in AWS, Microsoft Azure, or Google Cloud Platform, and will have experienced the benefits of event-driven technology for yourself.






This hands-on guide dives into the basis of serverless architectures and how to build them using Node.js as a programming language, Visual Studio Code for code editing, and Postman for quickly and securely developing applications without the hassle of configuring and maintaining infrastructure on three public cloud platforms.





What you will learn



  • Understand the benefts of serverless computing and know when to use it


  • Develop serverless applications on AWS, Azure, and Google Cloud


  • Get to grips with Function as a Service (FaaS)


  • Apply triggers to serverless functions


  • Build event-driven apps using serverless frameworks


  • Use the Node.js programming language to build serverless apps


  • Use code editors, such as Visual Studio Code, as development environments


  • Master the best development practices for creating scalable and practical solutions





Who this book is for



This book is targeted towards developers, system administrators or any stakeholder working in the Serverless environment and want to understand how functions work.







Basic idea of serverless architecture can be an added advantage

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

EPUB

Seitenzahl: 292

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 Serverless Computing

 

 

 

 

 

 

Build, run, and orchestrate serverless applications using AWS Lambda, Microsoft Azure Functions, and Google Cloud Functions

 

 

 

 

 

 

 

 

 

Kuldeep Chowhan

 

 

 

 

 

 

 

 

 

 

 

BIRMINGHAM - MUMBAI

Hands-On Serverless Computing

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(s), 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:Priyanka DeshpandeTechnical Editor: Manish ShanbhagCopy Editor: Safis EditingProject Coordinator: Virginia DiasProofreader: Safis EditingIndexer:Rekha NairGraphics: Tom ScariaProduction Coordinator: Nilesh Mohite

First published: July 2018

Production reference: 1200718

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

ISBN 978-1-78883-665-4

www.packtpub.com

 

To my lovely wife, Priya, who has always accepted me and supported my drive and ambitions. You are and always will be my loving partner throughout our joint life journey. My loving daughter, Myra, this is for you.
– Kuldeep
 
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

PacktPub.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.PacktPub.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.PacktPub.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.

Foreword

Cloud computing has been my passion for years. Ever since I started focusing on this area, advances in automation and software have continually amazed me. This amazement fueled the inspiration for my blog, Cloud Musings (http://blog.govcloudnetwork.com). Now in its tenth year, the blog's content has matured from explaining the basics of cloud computing to addressing its advantages from a business standpoint. Now that the second decade of the cloud computing era is upon us, why are the standard IaaS, PaaS, and SaaS models all of a sudden being replaced with serverless computing and the new Function as a Service (FaaS) model? Is this the end of cloud computing as we know it? Is my career as an application developer about to change again?

Luckily for many of us, cloud computing is not going away. Serverless computing, in fact, represents the next stage in cloud maturation. Although a misnomer, FaaS takes technology abstraction to the next level by completely removing infrastructure considerations from the developer's plate. With serverless computing, developers can now develop, deploy, and run applications without needing to think about provisioning servers. Developers don't even need to worry about managing or even scaling the infrastructure. All of these headaches are taken care of by the cloud service provider.

Similar to how the Large Hadron Collider explores and discovers elementary particles, the FaaS approach drives developers toward discovering, and in this domain, creating single-purpose blocks of code. Putting this in another way, just like physicists have abandoned the atom and accepted fermions and bosons as the most elementary particles, software developers must now abandon monolithic applications and microservices to accept the function block.

Hands-On Serverless Computing does not stop at explaining this new worldview. It gives the modern developer much-needed tools for creating and deploying serverless applications to AWS, Microsoft Azure, and the Google Cloud Platform (GCP). In providing his expert guidance, Kuldeep Chowhan goes into depth on development environments such as Visual Studio, Node.js, and JavaScript. He even tackles application testing with Postman.

If you are a developer and want to participate in cloud computing's future, you must accept this book as your serverless computing bible. Ignoring this inevitable change is like ignoring the microprocessor, object-oriented code, and the internet.

Kevin L. Jackson

Contributors

About the author

Kuldeep Chowhan is a Principal Software Developer at Expedia Group. He has been involved in building tools and platforms for the last 5+ years at Expedia. He has extensive experience on using serverless technologies on AWS (such as AWS Lambda, API Gateway, and DynamoDB) through Node.js. He has built a Platform as a Service (PaaS) tool for the automated creation of source code, a CI/CD pipeline, and a fully automated pipeline for deploying Docker containers/AWS Lambda. He is also passionate about CI/CD and DevOps.

I would like to thank my wife, Priya, and my mother-in-law, Durga Rani. I would also like to extend my gratitude to my mom, Durga, my dad and my two sisters – Sudha and Sai  for their support over the years.A big thanks to entire Packt team, Priyanka Deshpande, Shrilekha Inani, and Manish Shanbhag, for supporting me while I was writing the book.

 

 

About the reviewer

Siva Gurunathan has over 10 years of experience in establishing and managing successful technology companies and has strong expertise in cloud computing, virtualization, networking, and information security. Having co-founded his first start-up at the age of 21, he had bootstrapped it into a multi-million dollar venture within 3 years. Siva is an alumni of IIM Bangalore and also has a double major in engineering from Bits, Pilani. He currently focuses on hybrid cloud initiatives, bridging public clouds and on-premises data centers.

 

 

 

 

 

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 Serverless Computing

Dedication

Packt Upsell

Why subscribe?

PacktPub.com

Foreword

Contributors

About the author

About the reviewer

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

What is Serverless Computing?

What is serverless computing?

Serverless and event-driven collision

What is FaaS?

State

Execution duration

Understanding cold start 

API gateway

The benefits of serverless computing

Reduced operational cost

Rapid development

Scaling costs

Easier operational management

Easier packaging and deployment

Time to market

What serverless computing is not

Comparison with PaaS

Comparison with containers

#NoOps

Limits to serverless computing

Infrastructure control

Long running application

Vendor lock-in

Cold start

Shared infrastructure

Server optimization is a thing of the past

Security concerns

Deployment of multiple functions

Limited number of testing tools

Summary

Development Environment, Tools, and SDKs

Development environment and tools

Visual Studio Code

Setting up Visual Studio Code

Hardware

Platforms

Additional Windows requirements

Additional Linux requirements

Installing on macOS

Launching VS Code from the Command Line

Manually adding Visual Studio Code to your path

Touch Bar support

Installing on Linux

Debian and Ubuntu-based distributions

RHEL, Fedora, and CentOS-based distributions

openSUSE and SLE-based distributions

AUR package for Arch Linux

Nix package for NixOS (or any Linux distribution using Nix package manager)

Installing the .rpm package manually

Installing on Windows

Icons are missing

Why are some icons not appearing in the workbench and editor?

Visual Studio Code User Interface

Basic layout

Side-by-side editing

Explorer window

Keyboard shortcuts

Node.js

Node Package Manager

Node.js installation

Installation steps

Node.js tutorial in VS Code

Running Hello Readers

Integrated Terminal

Postman

Installation

Installing on macOS

Installing on Windows

Linux installation

Updating Postman – native app (macOS, Windows, and Linux)

Postman Echo

Sending the first request using Postman

How does this work in Postman?

SDKs

AWS Node.js SDK

Installation

Configuration

Microsoft Azure Node.js SDK

Installation

Configuration/Authentication

Google Cloud Node.js SDK

Installation

Configuration/authentication

Summary

Getting Started with AWS Lambda

What is AWS Lambda?

How does AWS Lambda work?

Use cases

Web apps

IOT and mobile backends

Extract, Transform, Load (ETL)

Data processing

Real-time processing

Execution environment

Environment variables

Execution context

AWS Lambda Function–Hello World

Function code – configuration

Publishing and testing your changes

Configuring options for AWS Lambda

Memory configuration

Execution time configuration

Network configuration

Function versioning and aliases

Traffic Shifting using aliases

Environment variables

Securing AWS Lambda using IAM

Authenticating

Access control

Identity-based policies (IAM policies)

Resource-based policies (Lambda function policies)

AWS Lambda permissions model

Summary

Triggers and Events for AWS Lambda

Triggers for AWS Lambda

API Gateway Trigger

AWS IoT Trigger

IoT Button

IoT rule

Alexa trigger

CloudFront trigger

CloudWatch trigger

CloudWatch Events

CloudWatch Logs

CodeCommit Trigger

Cognito Trigger

Scheduled Events Trigger

AWS Config Trigger

DynamoDB Trigger

Kinesis Trigger

Amazon Kinesis Data Streams

Amazon Kinesis Data Firehose

S3 Trigger

SNS Trigger

Summary

Your First Serverless Application on AWS

Technical requirements

Your first serverless app (using the AWS Console)

Creating a function

Testing the function

Updating the function

Publishing a new version

Creating an alias for a Lambda function

Your first serverless app (using the AWS SAM)

Creating a function

AWS SAM

Creating a SAM template for your serverless app

Testing a serverless app locally

Publishing a serverless app

Packaging a serverless app

Deploying a serverless app

Summary

Serverless Orchestration on AWS

What is AWS Step Functions?

How does AWS Step Functions work?

App using sequential steps

App using branching steps

App using parallel steps

Operational visibility

Creating your first state machine 

State machine using Lambdas

Summary

Getting Started with Azure Functions

An introduction to Azure Functions

Azure serverless platform

Compute

Database

Storage

Messaging

Security

Orchestration

API Management

Azure Function Proxies

Analytics

Azure portal 

Dashboards

Azure Cloud Shell

Azure Functions console

Configuring Azure Functions

Function app settings

Runtime

Deployment slots

Hosting plan

Consumption plan

App Service plan

Authorization keys

Platform features

Application settings

SSH

Kudu – Advanced tools

API Definition

Summary

Triggers and Bindings for Azure Functions

Azure Function triggers and bindings

Example binding and trigger

Azure services–triggers and bindings

Azure Blob storage

Trigger

Bindings

Azure Cosmos DB

Trigger

Azure Event Grid

HTTP and webhook bindings

HTTP trigger

Webhook trigger

Timer trigger

Summary

Your First Serverless Application on Azure

Technical requirements

Your first serverless app (using the Azure portal)

Creating an HTTP trigger-based function

Testing Azure Functions

Managing Azure Functions

Triggers and bindings

Authorization level

Function and host keys

Monitoring your Azure Function

Function proxies

Generating automation script

Your first Serverless app (using Azure Functions Core Tools)

Azure Functions Core Tools

macOS

Windows

Visual Studio Code

Create a local Azure Function app

Create a local Azure Function

Publishing the local Azure Function app

Summary

Getting Started with Google Cloud Functions

Google Cloud Serverless Platform

Application development

Google App Engine

Google Cloud Functions

Analytics and Machine Learning

An Introduction to Google Cloud Functions

Google Cloud Console

Creating a Google Cloud project

Google Cloud Project Dashboard

Google Cloud Shell

Google Cloud Functions Console

Access Control using IAM

Cloud Functions runtime service account

Cloud Functions Service account

Creating a Google Cloud Functions user

Configuring Google Cloud Functions

Types of Google Cloud Functions

Configuration options

Summary

Triggers and Events for Google Cloud Functions

Technical requirements

Events

Event parameter

Triggers

Google Cloud Storage

Google Cloud Pub/Sub

HTTP triggers

Handing different HTTP methods

Summary

Your First Serverless Application on Google Cloud

Technical requirements

Your first serverless app (using the Google Cloud Console)

Creating a Google Cloud Function

Testing a Google Cloud Function

Testing using Postman

Viewing logs for Google Cloud Functions

Your first serverless app (on a local workstation)

gcloud CLI

What is gcloud?

Installing gcloud

macOS

Windows

gcloud beta commands

Initializing the gcloud CLI

Creating a Google Cloud Function

Deploying a Google Cloud Function

Summary

Reference Architecture for a Web App

Technical requirements

Reference architecture

Friendly domain name

SSL/TLS certificate

Amazon API Gateway + AWS Lambda

Amazon DynamoDB

Hotel search

Lambda Function + API Gateway

Amazon DynamoDB

Add to cart

Lambda Function + API Gateway

Amazon DynamoDB

Summary

Reference Architecture for a Real-time File Processing

Technical requirements

Reference architecture

S3 bucket

Amazon Simple Notification Service

AWS Lambda

Photo processing application

Three Lambda functions

S3 Bucket + Amazon SNS

Summary

Other Books You May Enjoy

Leave a review - let other readers know what you think

Preface

Serverless computing allows you to build and run applications and services without thinking about servers. Serverless applications don't require you to provision, scale, and manage any servers. You can build them for nearly any type of application or backend service, and everything required to run and scale your application with high availability is handled for you. Building serverless applications means that your developers can focus on their core product instead of worrying about managing and operating servers or runtimes, either in the cloud or on premises. This reduced overhead lets developers reclaim time and energy that can be spent on developing great products that scale and are reliable.

This book teaches the basics of serverless computing and explains how to build event-driven apps using serverless frameworks on three public cloud platforms: AWS, Microsoft Azure, and Google Cloud. This hands-on guide dives into the basis of serverless architectures and how to build them using Node.js, Visual Studio Code for code editing, and Postman. This book teaches you how to quickly and securely develop applications without the hassle of configuring and maintaining infrastructure on three public cloud platforms.

You will learn how to harness serverless technology to rapidly reduce production time and minimize your costs, while still having the freedom to customize your code without hindering functionality. Upon completion of the book, you will have the knowledge and resources to build your own serverless application hosted in AWS, Microsoft Azure, or Google Cloud Platform, and will have experienced the benefits of event-driven technology for yourself. You will apply the fundamentals of serverless technology from the ground up, and will come away with a greater understanding of its power and how to make it work for you.

Who this book is for

This book is intended to be read by developers, architects, system administrators, or any stakeholders working in the serverless environment who want to understand how functions work and how to build them.

What this book covers

This book provides practical guidance and readers will learn about the following:

Serverless computing, the benefits it provides, and when to use it

What serverless computing 

isn't

Function as a Service (FaaS) and the different technologies that are provided by three public cloud providers: AWS Lambda, Azure Functions, and Google Cloud Functions

Different triggers that you can apply to your serverless functions in AWS, Microsoft Azure, and Google Cloud Platform

How to build serverless application across three public cloud providers using code samples

How to use programming languages such as Node.js and code editors such as Visual Studio Code to set up your development environment to build serverless applications

Best development practices with serverless computing to create scalable and practical solutions

Chapter 1, What is Serverless Computing?, introduces readers to the concept of serverless computing, use cases of serverless computing analysis, FaaS, the benefits of serverless computing, and what serverless computing is and isn't.

Chapter 2, Development Environment, Tools, and SDKs, introduces readers to the programming language and the tools that are required to write their serverless applications. It introduces the different SDKs that AWS, Microsoft Azure, and Google Cloud provide to write serverless applications.

Chapter 3, Getting Started with AWS Lambda, introduces readers to AWS Lambda, goes into depth about how AWS Lambda works, provides configuration options for AWS Lambda, and explains how to secure AWS Lambda.

Chapter 4, Triggers and Events for AWS Lambda, introduces readers to the different triggers and events available for AWS Lambda.

Chapter 5, Your First Serverless Application on AWS, teaches readers how to write serverless applications to run on AWS using Node.js, how to deploy serverless applications to AWS, how to test the serverless application, and how to trigger the serverless application using Amazon API Gateway.

Chapter 6, Serverless Orchestration on AWS, teaches readers how to orchestrate and manage the state of serverless applications on AWS using AWS step function.

Chapter 7, Getting Started with Azure Functions, introduces readers to Azure Functions and goes into depth about how Azure Functions works. It also explains the configuration options for Azure Functions and how to secure Azure Functions.

Chapter 8, Triggers and Bindings for Azure Functions, introduces readers to the different triggers and events available for Azure Functions.

Chapter 9, Your First Serverless Application on Azure, teaches readers how to write serverless applications to run on Azure using Node.js, how to deploy serverless applications to Azure, how to test serverless applications, and how to trigger serverless applications using Azure API Management.

Chapter 10, Getting Started with Google Cloud Functions, introduces readers to Google Cloud Functions, goes into depth about how Google Cloud Functions works, covers the configuration options for Google Cloud Functions, and explains how to secure Google Cloud Functions.

Chapter 11, Triggers and Events for Google Cloud Functions, introduces readers to the different triggers and events available for Google Cloud Functions.

Chapter 12, Your First Serverless Application on Google Cloud, teaches readers how to write serverless applications to run on Google Cloud using Node.js, how to deploy serverless applications to Google Cloud, how to test serverless applications, and how to trigger the serverless application using HTTP triggers.

Chapter 13, Reference Architecture for a Web App, provides a reference architecture for creating a web application using serverless computing on AWS.

Chapter 14, Reference Architecture for a Real-Time File Processing, provides a reference architecture for real-time file processing using serverless computing on AWS.

To get the most out of this book

Knowledge of serverless architectures and frameworks, as well as Node.js, would be an advantage. Sufficient information will be provided to those new to this field.

Chapter 2, Development Environment, Tools, and SDKs, has the installation instructions for the software that you will need to develop serverless applications on your workstation. Please make sure to go through it.

Download the example code files

You can download the example code files for this book from your account at www.packtpub.com. If you purchased this book elsewhere, you can visit www.packtpub.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.packtpub.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 at https://github.com/PacktPublishing/Hands-On-Serverless-Computing. 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 at https://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: http://www.packtpub.com/sites/default/files/downloads/HandsOnServerlessComputing_ColorImages.pdf.

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "The actual event data is available within the data property of the event object."

A block of code is set as follows:

function handleGET(req, res) { res.status(200).send('Hello from HTTP Google Cloud Function!'); } function handlePUT(req, res) { res.status(403).send("Forbidden, you don't have access"); }

Any command-line input or output is written as follows:

curl

-

X POST https

://<

YOUR_REGION

>-<

YOUR_PROJECT_ID

>.

cloudfunctions

.

net

/

<FUNCTION_NAME>

-

H

"Content-Type:application/json"

--

data

'{"name":"Kuldeep"}'

Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example:

"Select the trigger type as Cloud Pub/Sub topic."

Warnings or important notes appear like this.
Tips and tricks appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: Email [email protected] and mention the book title in the subject of your message. If you have questions about any aspect of this book, please 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.packtpub.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 packtpub.com.

What is Serverless Computing?

Before we start creating serverless applications to run in Amazon Web Services (AWS), Microsoft Azure, and the Google Cloud Platform (GCP), let's learn about what serverless computing is. We will learn about how it is being used, and about Function as a Service (FaaS) and the benefits that serverless computing provides. Readers will also learn about what serverless computing isn't.

In this chapter, we will cover the following topics:

What is serverless computing?

Use cases of serverless computing

Unpacking FaaS

What serverless computing is not

The benefits of serverless computing

Best practices to get the maximum benefits out of serverless computing

What is serverless computing?

Serverless applications still require servers to run; hence, the term is a misnomer.  Serverless computing adds a layer of abstraction on top of a cloud infrastructure, so developers need not worry about provisioning and managing physical or virtual servers in the cloud. Serverless computing gives you the capability to develop, deploy, and run applications without having to think about provisioning and management of servers. Serverless computing doesn't need you to provision, manage, and scale the infrastructure required to execute your application. The cloud provider automatically provisions the infrastructure required for your function to run and scale your serverless application with high availability.

In most cases, when people think of serverless computing, they are likely to think of applications with backends that run on cloud providers, such as AWS, that are fully managed, are event triggered, and are ephemeral, lasting only for the invocation that runs within a stateless container. While serverless applications are fully managed and hosted by cloud providers, such as AWS, it is a misinterpretation to say that the applications are completely running serverless. Servers are still involved in the execution of these serverless applications; it is just that these are managed by cloud providers, such as AWS. One way to think about these serverless applications is as FaaS. The most popular implementation of FaaS at the moment is AWS Lambda. However, there are other FaaS implementations from Microsoft Azure called Azure Functions, from GCP called Cloud Functions, and from the open source serverless platform from Apache called OpenWhisk. 

Serverless computing is all about the modern developer's expanding frame of reference.

What we have seen is that the atomic unit of scale has been changing from the virtual machine to the container, and if you take this one step further, we start to see something called function—a single-purpose block of code. It is something you can analyze very easily. It can:

Process an image

Transform a piece of data

Encode a piece of video

The following diagram depicts the difference between Monolothic, Microservice, and FaaS architectures:

Monolithic versus Microservice versus FaaS

Developing serverless applications means that you can focus on solving the core business problem instead of spending time on how to operate and manage runtimes, or compute infrastructure, either in on-premises, or in the cloud. With this reduced overhead,  developers can reclaim the time and energy that they would usually spend on developing solutions to provision, manage, and scale the applications that are highly available and reliable. I will touch upon this more later in the book.

The real goal of the serverless computing movement is to provide a high level of abstraction of the compute infrastructure so that developers can focus on solving critical business problems, deploy them rapidly, and reduce the time it takes for business ideas to be marketed, as opposed to the time it takes if you use traditional infrastructure for your applications.

Serverless and event-driven collision

Event-driven computation is an architecture pattern that emphasizes action in response to or based on the receptions of events. This pattern promotes loosely coupled services and ensures that a function executes only when it is triggered. It also encourages developers to think about the type of events and responses a function needs in order to handle these events before programming the functions: 

Event-driven architecture example

A system built with event-driven architecture consists of Event Producers that produce a stream of events that are ingested using Event Ingestion, and then Event Consumers that listen for the events, as shown in the preceding diagram.

Events are delivered to consumers in near real time so that they can respond immediately to the events as they happen. Event producers are decoupled from the event consumers. As they are decoupled, the producers don't know which consumers are listening to the events that they produce. Event consumers are also decoupled from one another, and every event consumer sees every events produced by the event producers.

Serverless applications are usually built by combining multiple functions (FaaS) using offerings, such as AWS Lamdba or Microsoft Azure Functions, together with external backend resources, such as Amazon S3, Amazon DynamoDB, and many more solutions to manage the state between invocations. The architecture that ties these multiple functions (FaaS) is event-driven architecture. By combining tools, such as AWS Lambda and Amazon S3, you can develop applications without having to think about the provision and management of the infrastructure. As this is a shift in architecture compared to how you might have operated so far, you would also need to change how data will flow through your application, which is made up of functions.

In this event-driven architecture, the functions are event consumers because they are expected to come alive when an event occurs and are responsible for processing it. Some examples of events that trigger serverless functions include the following:

API requests

Scheduled events

Events in object storage

Events in databases

Notification events

What is FaaS?

I've mentioned FaaS a few times already, so let's dig into what it really means. Serverless computing involves code that runs as a service on an infrastructure that is fully managed by the cloud provider. This is automatically provisioned, based on an event, and is automatically scaled to ensure high availability. You can think of this as FaaS that run on stateless, ephemeral containers created and maintained by the cloud provider. You might have already come across terms such as Software as a Service (SaaS), Infrastructure as a Service (IaaS), and Platform as a Service (PaaS). Let's look at what they mean. SaaS is a form of cloud computing in which software is licensed based on a subscription, hosted centrally, and is delivered remotely by the provider over the internet. Examples of SaaS are Google Apps, Citrix GoToMeeting, and Concur. IaaS is a form of cloud computing where the provision and management of compute infrastructure resources occur over the internet, scales up quickly, and you pay for what you use. Examples of IaaS are Azure Virtual Machines and AWS EC2. PaaS is a form of cloud computing where the software and infrastructure that are needed for application development are provided over the internet by the provider. Examples of PaaS are AWS Beanstalk and Azure App Services. 

Let's also look at AWS Lambda to learn more about FaaS.

AWS Lambda helps you run code without supplying or administrating servers. You pay only for the total time you consume—no charge is applicable when your code is not running. Using Lambda, one can run code for virtually any type of application or backend service—all with zero administration. We need to upload the code and Lambda looks into everything required to run and scale your code with high availability. You can set up your code to automatically trigger from other AWS services or call it directly from any web or mobile app.

Let's look at features that AWS Lambda offers that fit into FaaS paradigm:

Essentially, FaaS runs code without having to provision and manage servers on your own and is executed based on an event rather than running all the time. With traditional architectures that involve containers or physical/virtual servers, you would need the servers be running all the time. As the infrastructure is used only based on the requirements, you achieve 100 percent server utilization, and cost savings are also huge as you pay only for the compute time you consume when the function/Lambda runs.

With FaaS solutions, you can run any type of application, which means there isn't a restriction on what languages you need to write the code in or on particular frameworks to be used. 

 For example, AWS Lambda functions can be written in JavaScript, Python, Go, C# programming languages, and any JVM language (Java, Scala, and so on). 

The deployment architecture for your code is also different from traditional systems, as there is no server to update yourself. Instead, you just upload your latest code to the cloud provider, AWS, and it takes care of making sure the new version of the code is used for subsequent executions.

AWS handles scaling of your function automatically based on the requests to process without any further configuration from us. If your function needs to be executed 10,000 times in parallel, AWS handles scaling up the infrastructure that is required to run your function 10,000 times in parallel. The containers that are executing your code are stateless, ephemeral with AWS provisioning, and destroyed only for the duration that is driven by the runtime needs.

In AWS, functions are triggered by different event types, such as S3 (file) updates, scheduled tasks based on a timer, messages sent to Kinesis Stream, messages sent to SNS topics, and many more event type triggers. 

AWS also allows functions to be triggered as a response to HTTP requests through Amazon API Gateway.

State

Functions, as they run in ephemeral containers, have significant restrictions when it comes to management of state. You need to design your functions in such a way that the subsequent run of your function will not be able to access state from a previous run. In short, you should develop your functions with the point of view that they are stateless.