没有合适的资源?快使用搜索试试~ 我知道了~
首页AWS Lambda In Action Chapter1
AWS Lambda In Action Chapter1
需积分: 10 15 下载量 154 浏览量
更新于2023-05-29
收藏 1.03MB PDF 举报
amazon web service中的lambda服务介绍第一章内容, 后续内容持续发布
资源详情
资源推荐
Username: Columbia University Book: AWS Lambda in Action: Event-driven serverlessapplications. No part of any chapter or book may be reproduced or
transmitted in any form by any means without the prior written permission for reprints and excerpts from the publisher of the book or chapter. Redistribution or
other use that violates the fair use privilege under U.S. copyright laws (see 17 USC107) or that otherwise violates these Terms of Service is strictly prohibited.
Violators will be prosecuted to the full extent of U.S. Federal and Massachusetts laws.
Chapter 1. Running functions in the cloud
This chapter covers
Understanding why functions can be the primitives of your application
Getting an overview of AWS Lambda
Using functions for the back end of your application
Building event-driven applications with functions
Calling functions from a client
In recent years, cloud computing has changed the way we think about and implement IT services, allowing companies of every size to build powerful and scalable
applications that could disrupt the industries in which they operated. Think of how Dropbox changed the way we use digital storage and share files with each other,
or how Spotify changed the way we buy and listen to music.
Those two companies started small, and needed the capacity to focus their time and resources on bringing their ideas to life quickly. In fact, one of the most
important advantages of cloud computing is that it frees developers from spending their time on tasks that don’t add real value to their work, such as managing and
scaling the infrastructure, patching the operating system (OS), or maintaining the software stack used to run their code. Cloud computing lets them concentrate on
the unique and important features they want to build.
You can use cloud computing to provide the infrastructure for your application, in the form of virtual servers, storage, network, load balancers, and so on. The
infrastructure can be scaled automatically using specific configurations. But with this approach you still need to prepare a whole environment to execute the code
you write. You install and prepare an operating system or a virtual environment; you choose and configure a programming framework; and finally, when the overall
stack is ready, you can plug in our code. Even if you use a container-based approach in building the environment, with tools such as Docker, you’re still in change of
managing versioning and updates of the containers you use.
Sometimes you need infrastructure-level access because you want to view or manage low-level resources. But you can also use cloud computing services that
abstract from the underlying infrastructure implementation, acting like a platform on top of which you deploy your own customizations. For example, you can have
services that provide you with a database, and you only need to plug in your data (together with a data model) without having to manage the installation and
availability of the database itself. Another example is services where you provide the code of your application, and a standard infrastructure to support the
execution of your application is automatically implemented.
If that’s true for a development environment, as soon as you get closer to production things become more complex and you may have to take care of the scalability
and availability of the solution. And you must never forget to think about security—considering who can do what, and on which resources—during the course of the
design and implementation of an application.
With the introduction of AWS Lambda, the abstraction layer is set higher, allowing developers to upload their code grouped in functions, and letting those functions
be executed by the platform. In this way you don’t have to manage the programming framework, the OS, or the availability and scalability. Each function has its own
configuration that will help you use standard security features provided by Amazon Web Services (AWS) to define what a function can do and on which resources.
Those functions can be invoked directly or can subscribe to events generated by other resources. When you subscribe a function to a resource such as a file
repository or a database, the function is automatically executed when something happens in that resource, depending on which kinds of events you’ve subscribed
to. For example, when a file has been uploaded or a database item has been modified, an AWS Lambda function can react to those changes and do something
with the new file or the updated data. If a picture has been uploaded, a function can create thumbnails to show the pictures on the screens with different
resolutions. If a new record is written in an operational database, a function can keep the data warehouse in sync. In this way you can design applications that are
driven by events.
Book graphical conventions
This book uses the following graphical conventions to help present information more clearly.
Using multiple functions together, some of them called directly from a user device, such as a smartphone, and other functions subscribed to multiple repositories,
such as a file share and a database, you can build a complete event-driven application. You can see a sample flow of a media-sharing application built in this way in
figure 1.1. Users use a mobile app to upload pictures and share them with their friends.
Figure 1.1. An event-driven, media-sharing application built using multiple AWS Lambda functions, some invoked directly by the mobile app. Other functions are subscribed to storage repositories such as a
file share or a database.
Note
Don’t worry if you don’t completely understand the flow of the application in figure 1.1. Reading this book, you’ll first learn the architectural principles used in the
design of event-driven applications, and then you’ll implement this media-sharing application using AWS Lambda together with an authentication service to
recognize users.
When using third-party software or a service not natively integrated with AWS Lambda, it’s still easy to use that component in an event-driven architecture, adding
the capacity to generate those events by using one of the AWS software development kits (SDKs), which are available for multiple platforms.
The event-driven approach not only simplifies the development of production environments, but also makes it easier to design and scale the logic of the
application. For example, let’s take a function that’s subscribed to the upload of a file in a repository. Every time this function is invoked, it extracts information from
the content of the file and writes this in a database table. You can think of this function as a logical connection between the file repository and the database table:
every time any component of the application—including the client—uploads a file, the subscribed events are triggered and, in this case, the database is updated.
As you add more features, the logic of any application becomes more and more complex to manage. But in this case you created a relationship between the file
repository and the database, and this connection works independently from the process that uploads the file. You’ll see more advantages of this approach in this
book, along with more practical examples.
If you’re building a new application for either a small startup or a large enterprise, the simplifications introduced by using functions as the building blocks of your
application will allow you to be more efficient in where to spend your time and faster in introducing new features to your users.
1.1. Introducing AWS Lambda
AWS Lambda is different from a traditional approach based on physical or virtual servers. You only need to give your logic, grouped in functions, and the service
itself takes care of executing the functions, if and when required, by managing the software stack used by the runtime you chose, the availability of the platform,
and the scalability of the infrastructure to sustain the throughput of the invocations.
Functions are executed in containers. Containers are a server virtualization method where the kernel of the OS implements multiple isolated environments. With
AWS Lambda, physical servers still execute the code, but because you don’t need to spend time managing them, it’s common to define this kind of approach as
serverless.
Tip
For more details on the execution environment used by Lambda functions, please visit http://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html.
When you create a new function with AWS Lambda, you choose a function name, create your code, and specify the configuration of the execution environment that
will be used to run the function, including the following:
The maximum memory size that can be used by the function
A timeout after which the function is terminated, even if it hasn’t completed
A role that describes what the function can do, and on which resources, using AWS Identity and Access Management (IAM)
Tip
When you choose the amount of memory you want for your function, you’re allocated proportional CPU power. For example, choosing 256 MB of memory allocates
approximately twice as much CPU power to your Lambda function as requesting 128 MB of memory and half as much CPU power as choosing 512 MB of memory.
AWS Lambda implements the execution of those functions with an efficient use of the underlying compute resources that allows for an interesting and innovative
cost model. With AWS Lambda you pay for
The number of invocations
The hundreds of milliseconds of execution time of all invocations, depending on the memory given to the functions
The execution time costs grow linearly with the memory: if you double the memory and keep the execution time the same, you double that part of the cost. To
enable you to get hands-on experience, a free tier allows you to use AWS Lambda without any cost. Each month there’s no charge for
The first one million invocations
The first 400,000 seconds of execution time with 1 GB of memory
If you use less memory, you have more compute time at no cost; for example, with 128 MB of memory (1 GB divided by 8) you can have up to 3.2 million seconds
of execution time (400,000 seconds multiplied by 8) per month. To give you a scale of the monthly free tier, 400,000 seconds corresponds to slightly more than 111
hours or 4.6 days, whereas 3.2 million seconds comes close to 889 hours or 37 days.
Tip
You’ll need an AWS account to follow the examples in this book. If you create a new AWS account, all the examples that I provide fall in the Free Tier and you’ll
have no costs to sustain. Please look here for more information on the AWS Free Tier and how to create a new AWS account: http://aws.amazon.com/free/.
Throughout the book we’ll use JavaScript (Node.js, actually) and Python in the examples, but other runtimes are available. For example, you can use Java and other
languages running on top of the Java Virtual Machine (JVM), such as Scala or Clojure. For object-oriented languages such as Java, the function you want to expose
is a method of an object.
To use platforms that aren’t supported by AWS Lambda, such as C or PHP, it’s possible to use one of the supported runtimes as a wrapper and bring together with
the function a static binary or anything that can be executed in the OS container used by the function. For example, a statically linked program written in C can be
embedded in the archive used to upload a function.
When you call a function with AWS Lambda, you provide an event and a context in the input:
The event is the way to send input parameters for your function and is expressed using JSON syntax.
The context is used by the service to describe the execution environment and how the event is received and processed.
剩余13页未读,继续阅读
lmhapxh
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- zigbee-cluster-library-specification
- JSBSim Reference Manual
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功