Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
MSc/PG Dip in CS
Department of Computer Science and Engineering,
University of Moratuwa.
7. Amazon Lambda 7
7.1. Asynchronous Model Example with AWS 7
7.2. Synchronous Model Example with AWS 8
8. Conclusion 8
9. References 9
1
1. Introduction
Cloud Computing is gradually taking over the world and it is becoming a technology that the
industry cant live without. This comes as no surprise as with the business drivers such as
capacity planning, cost reduction and organizational agility, Cloud Computing has become
the most prefered choice for most organizations. One of the main concepts of Cloud
Computing is that the technology is abstracted away from the user, which basically means
that the users does not have to worry about how the cloud service is provided and they can
simply focus on using the cloud services. Having this concept in mind cloud providers try to
provide everything as a service and so far the main delivery models are Infrastructure as a
Service (IaaS), Platform as a Service (PaaS) and Software as a Service (SaaS).
The other and the more recent use of this term is to the refer the applications where some
amount of server-side logic is still written by the application developer but unlike traditional
architectures, this is run in stateless compute containers that are event-triggered, ephemeral
(may only last for one invocation), and fully managed by a 3rd party. That is where the term
Function as a Service (FaaS) comes in and both these terms the FaaS and Serverless
Architecture became popular with the AWS Lambda[1] launch in 2014 and even more so
after Amazons API Gateway[2] launched in July 2015. AWS Lambda is the most popular
2
FaaS provider today and others like Google Cloud Functions[3] are becoming popular as
well. These will be discussed further in coming sections.
Going into a bit more detail of the features of Serverless Architecture and FaaS, the first one
is that it allows users to write custom server-side function and run it accordingly. It is not a
very huge amount of code unlike the case where an application is developed on a PaaS. It is
a function which is specific to a certain small task. One such example would be creating a
thumbnail from an image or perhaps running a database query. These examples will be
further discussed in coming sections. FaaS offerings do not require coding to a specific
framework or library. FaaS functions are regular applications when it comes to language
and environment.
Serverless Architecture is event triggered. Its architectured in a such a way that there has
to be an event source which triggers the service to run. When comparing with other cloud
delivery models, this is not something we see in these other models. This is specific to FaaS.
Another feature is that FaaS is ephemeral and what it means is that the execution of the
service may lasts a very short time. Unlike in a case like SaaS or PaaS for that matter where
service is running continuously, in FaaS the service may only run for a very short time period
for a given trigger and thats it. Of course there is some sort of a service running to monitor
the incoming triggers but the computing service is not continuously running for long time
periods. Along with this with FaaS horizontal scaling is completely automatic, elastic, and
managed by the provider. If a user requires a system which can process 100 requests in
parallel the cloud provider will handle that automatically and user dont need to give any sort
of extra configuration for this.
Another quality of FaaS is that it is stateless. Persisting state between two executions of
the same function is not possible in the general design. In cases where storing state is
required it should be stored externally.
Collecting metrics from web application with a REST API in a high load scenario.
Extracting and storing data from incoming emails containing order and status
information.
Creating a REST API providing a standard CRUD backend.
Collecting and transforming data within an ETL process in a big data scenario.
Analyzing log messages from a real-time data stream.
3
Building a chatbot that is interacting with multiple APIs in the background.
There are a number of FaaS providers today, some proprietary providers such as AWS
Lambda[1], Google Cloud Functions[3], Azure Functions[4] and some open source ones
such as OpenWhisk[5]. Looking at the technologies that made FaaS possible, two major
technologies are the containers and container orchestration technologies.
4.1. Containers
Containers are a new type of virtualization and they fall under the category of operating
system level virtualization. Containers share the underlying kernel of the host operating
system and they allow multiple isolated user-space instances (containers). Today there a
number of container platforms such as Docker[6], LXD[7] and out of those Docker is the
most widely used platform. Following diagram shows the above mentioned container
architecture with Docker.
4
Figure 1 : Docker Container Architecture.
Image taken from [8]
When we compare virtual machines (VM) with containers there are several advantages that
container bring to the table. One is that unlike in VMs containers usually impose little to no
overhead ensuring most of the machines resources are available to the applications running
in containers. Along with that one of the important point in which containers beat VMs is the
time to startup and shutdown. Containers can be taken up and down in a matter of seconds
whereas VMs take a lot more time than that. Containers get this advantage due to the fact
that they share the host OS kernel. Having faster up and down times makes containers ideal
for FaaS due to the trigger driven architecture FaaS. Along with the above mentioned
advantages containers do have a few disadvantages as well. One is that it limits the
operating system choice of virtualization. The issue here is that the guest operating system
must be identical or similar to host operating systems. However this the container platforms
have now induced mechanisms to minimize this issue somewhat as well.
A single container by itself is not very much useful. In enterprise applications managing of
clusters of containers is required. Container orchestration platforms extend lifecycle
management capabilities to complex, multi-container workloads deployed on a cluster of
machines. These platforms abstract the host infrastructure and allow users to treat the entire
cluster as a single deployment target. Basic features of container orchestration tools
includes ability to automate all aspects of application management from initial placement,
scheduling and deployment to steady-state activities such as update, deployment, and
health monitoring functions that support scaling and failover. There are dozens of container
orchestration platforms such as Kubernetes[9], Docker Swarm, Mesosphere Marathon and
some of them provided as cloud solutions such as AWS Elastic Container Service (AWS
ECS), Google Container Engine and Azure Container Service (ACS).
5
5. Benefits of Serverless Architecture
This section will focus on the benefits that Serverless Architecture or FaaS brings. First and
foremost benefit is the reduced operational cost FaaS provides. This benefit is not too
different from what we get for other cloud delivery models such as IaaS or PaaS however
depending on the application FaaS can be more advantageous than the other two. One such
application is an application which get occasional requests. In such a scenario, unlike in
PaaS or SaaS users dont have to keep the servers up and running 24/7 and with FaaS they
only have to pay for the actual computation that is required. Another instance where FaaS is
better is when the traffic is highly inconsistent or spiky perhaps. In cases like these, if it is
PaaS or IaaS the average number of servers users have to keep up an running is much
larger because handling spikes is not easy with those solutions with VMs. Therefore in these
cases FaaS is much better as horizontal scaling is completely automatic, elastic, and
managed by the provider. Scaling benefits by itself can be mentioned as an advantage of
FaaS since scaling is performed by the provider on every request / event and the user no
longer need to even think about the question of how many concurrent requests the system
can handle before running out of memory or seeing too much of a performance hit, at least
not within the FaaS hosted components.
Another advantage we can have with FaaS is reduced packaging and deployment
complexity. FaaS function is very simple compared with an entire server. For a user who is
just getting started, he/she may not even need to package anything and just code in the
FaaS providers console. Along with these with FaaS time to market is much less as well and
experimentation is much more quicker.
6
7. Amazon Lambda
AWS Lambda is the most popular FaaS provider and in fact it is AWS who brought the
Serverless Architecture term into the market with the release of Amazon Lambda in 2014. In
Lambda users can use events such as an update to Dynamo DB, uploads to Amazon S3
bucket, data in Amazon Kinesis streams or even in-app activity as triggers for the Lambda
functions. Lambda provides the computing infrastructure and a runtime environment for
JavaScript (Node.js), Java, Python, and .NET Core (C#). I n AWS users are charged for
every 100ms their code executes and the number of times the code is triggered.
In this section we will look at one use case of AWS Lambda which uses the asynchronous
model. The scenario is that user wants to create a thumbnail of image uploaded to Simple
Storage Service (S3) bucket.
7
7.2. Synchronous Model Example with AWS
A typical use case for the synchronous model is a REST API. An incoming HTTPS request is
triggering a serverless function. The caller waits until the function returns a result.
8. Conclusion
FaaS concept is still very new and it is a concept which is yet to be proven in large scale
enterprise applications. There is still room for FaaS to improve and its drawbacks. One area
where they could improve is tooling. The lack of tooling for deployment, application
bundling, configuration, monitoring, logging and debugging is an issue which need to be
addressed. Another such area for improvement is state management. Even without state
FaaS is pretty good for many applications but there can be cases where storing state
externally might not be enough and perhaps require state to be stored within functions. Its
obvious that Serverless Architecture is not the option for every scenario or problem but it is
clear that with the benefits it provides there is a significant interest throughout the industry
for Serverless.
8
9. References
[1] AWS Lambda - Serverless Compute [Online]. Available :
https://aws.amazon.com/lambda/
[2] Amazon API Gateway [Online]. Available : https://aws.amazon.com/api-gateway/
[3] Cloud Functions - Serverless Environment to Build and Connect Cloud Services | Google
Cloud Platform [Online]. Available : https://cloud.google.com/functions/
[4] Azure FunctionsServerless Architecture | Microsoft Azure [Online]. Avaliable :
https://azure.microsoft.com/en-us/services/functions/
[5] Apache OpenWhisk is a serverless, open source cloud platform [Online]. Available :
http://openwhisk.org/
[6] Docker - Build, Ship, and Run Any App, Anywhere [Online]. Available :
https://www.docker.com/
[7] Linux Containers - LXD - Introduction [Online]. Available : https://linuxcontainers.org/lxd/
[8] For CTOs: the no-nonsense way to accelerate your business with containers, 2017.
[9] Kubernetes | Production-Grade Container Orchestration [Online]. Available :
https://kubernetes.io/
[10] A. Wittig, The DZone Guide to Cloud Native Development & Deployment Volume IV -
Serverless Architectures on AWS 2017.