Mastering AWS Lambda
eBook - ePub

Mastering AWS Lambda

  1. 300 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Mastering AWS Lambda

About this book

Build cost-effective and highly scalable Serverless applications using AWS Lambda.About This Book• Leverage AWS Lambda to significantly lower your infrastructure costs and deploy out massively scalable, event-driven systems and applications• Learn how to design and build Lambda functions using real-world examples and implementation scenarios• Explore the Serverless ecosystem with a variety of toolsets and AWS services including DynamoDB, API Gateway, and much more!Who This Book Is ForIf you are a Cloud administrator and/or developer who wishes to explore, learn, and leverage AWS Lambda to design, build, and deploy Serverless applications in the cloud, then this is the book for you! The book assumes you have some prior knowledge and hands-on experience with AWS core services such as EC2, IAM, S3, along with the knowledge to work with any popular programming language such as Node.Js, Java, C#, and so on.What You Will Learn• Understand the hype, significance, and business benefits of Serverless computing and applications• Plunge into the Serverless world of AWS Lambda and master its core components and how it works• Find out how to effectively and efficiently design, develop, and test Lambda functions using Node.js, along with some keen coding insights and best practices• Explore best practices to effectively monitor and troubleshoot Serverless applications using AWS CloudWatch and other third-party services in the form of Datadog and Loggly• Quickly design and develop Serverless applications by leveraging AWS Lambda, DynamoDB, and API Gateway using the Serverless Application Framework (SAF) and other AWS services such as Step Functions• Explore a rich variety of real-world Serverless use cases with Lambda and see how you can apply it to your environmentsIn DetailAWS is recognized as one of the biggest market leaders for cloud computing and why not? It has evolved a lot since the time it started out by providing just basic services such as EC2 and S3 and today; they go all the way from IoT to Machine Learning, Image recognition, Chatbot Frameworks, and much more! One of those recent services that is also gaining a lot of traction is AWS Lambda! Although seemingly simple and easy to use, Lambda is a highly effective and scalable compute service that provides developers with a powerful platform to design and develop Serverless event-driven systems and applications.The book begins with a high-level introduction into the world of Serverless computing and its advantages and use cases, followed by a deep dive into AWS Lambda! You'll learn what services AWS Lambda provides to developers; how to design, write, and test Lambda functions; as well as monitor and troubleshoot them. The book is designed and accompanied with a vast variety of real-world examples, use cases, and code samples that will enable you to get started on your Serverless applications quickly.By the end of the book, you will have gained all the skills required to work with AWS Lambda services!Style and approachThis step-by-step guide will help you build Serverless applications and run Serverless workloads using the AWS Lambda service. You'll be able to get started with it in a matter of minutes with easy-to-follow code snippets and examples.

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription.
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn more here.
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes! You can use the Perlego app on both iOS or Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Yes, you can access Mastering AWS Lambda by Yohan Wadia, Udita Gupta in PDF and/or ePUB format, as well as other popular books in Computer Science & Cloud Computing. We have over one million books available in our catalogue for you to explore.

Information

Event-Driven Model

So far, we have learned a thing or two about serverless and AWS Lambda. We started off by understanding the entire concept behind serverless architecture and, later, dived into the amazing world of serverless computing with AWS Lambda. We learned how to effectively write, develop, package, and test Lambda functions and also picked up on a few best practices and recommendations along the way.
From this chapter onwards, we will be taking a slightly different approach to understand how few core functionalities of Lambda actually work. For example, how do you trigger Lambda functions to execute based on a trigger? That's exactly what this chapter is going to be all about. In this chapter, we will be covering the following topics:
  • What event-driven model is all about
  • Understanding the event-driven model of Lambda along with a few simple event-driven architectures for better understanding
  • Getting started with simple event-driven use cases of Lambda that range from basic data manipulations to automated infrastructure management and so on
So, without any more delay, let's get started!

Introducing event-driven architectures

Till now we have been working and understanding Lambda using our trusty calculator example code, that simply accepts few parameters and values as inputs, and, when run, provides you with some desired output. What you may not have noticed is that the inputs that we were providing for the code to run were actually part of an event, that would trigger the code into running. Similarly, you can write Lambda functions that get activated or triggered when a particular message or event is generated. This is perhaps one of the biggest reasons why I love Lambda so much and why Lambda is so much better than your traditional EC2 instances! But, before we begin exploring the various triggers and events that Lambda can respond to, let us understand what Event Driven architectures are all about and how are they so useful.
Event-driven architecture (EDA) is basically a software architecture pattern that deals with the generation, detection, consumption, and reaction to one or more events. Events can be anything; from simple messages, notification calls, to state changes. In our AWS Lambda case, events can be something such as an object getting uploaded to an S3 bucket or a row getting deleted from a DynamoDB table and so on.
An event-driven architecture in general comprises of three essential pieces: an event emitter, an event channel, and an event consumer. In simpler terms, the entire process flow looks a bit like the following image:
The event emitters are responsible for gathering state changes or events that occur within the event-driven system. They simply get the event and send it to the next step of the process which is the event channel. Here, the channels serve two purposes; one is to simply channel or funnel the event to a particular waiting consumer where the event will be processed and acted upon. Alternatively, the channel itself can react to the event, and perform some level of pre-processing on the event and then send it down to the consumers for the final processing as represented earlier.
Now, keeping these basics in mind, let us look at how AWS Lambda enables event-driven architecture along with a few easy to understand use cases as well.

Understanding events and AWS Lambda

Lambda works in a very similar way, as explained in the previous section. For instance, the emitters and channels act as the Lambda event source while the functions that we have been creating all this time act as the event consumers.
All in all, when an event is triggered by a particular AWS service, or even from an external source such as an application, that event gets mapped to a particular Lambda function which in turn, executes an action based on the code that you have written for it. This one-to-one mapping of events with their corresponding Lambda functions is what we call as Event Source Mapping and it is responsible for the automatic invocation of your Lambda functions whenever an event is fired.
There are two main categories of event sources supported by Lambda:
  • AWS services: Lambda supports a few of AWS's services as preconfigured event sources that you can use to develop easy event-driven systems with. Few of the services namely S3, SNS, SES, Cognito, CloudFromation, CloudWatch fall under a branch relatively termed as regular AWS services; whereas DynamoDB and Kinesis fall under something called as stream based services as in both these cases, Lambda polls the streams for any updates and when it does find one, it triggers the corresponding function to run. In this chapter, we will be looking at few of the commonly used AWS services used as event mappings and how you can leverage them to perform simple tasks for your cloud environment.
  • Custom applications: Custom applications are your own home grown applications or external world entities that can generate their own events. This can be anything from a simple web based application or even mobile device.
Before we actually begin with the event mapping examples and use cases, let us quickly glance through some of the architecture patterns and use cases where Lambda's event mapping system comes into play.

Lambda architecture patterns

In this section, we will be looking at some of the commonly used Lambda architecture patterns that you can use as blueprints for building your own serverless and event based applications.
  • Serverless microservices: Microservices are designed and developed to be independent and self-sufficient, which is exactly why they are an amazing candidate for running with the help of Lambda. A Lambda function too, in its own is an independent code that can execute for a finite time when triggered by an external source. The only downside here is that, because of the deep granularity, the sheer number of microservices and the corresponding Lambda functions that you will end up with will be really high. Managing that many functions can be a challenge especially when you need to do changes, new deployments and so on.
In the following depiction, we can see a number of Lambda functions hosting microservices frontended by an API Gateway and having one or more databases as backends.
  • Serverless multi-tier applications: Perhaps one of the most commonly used architecture patterns, Lambda is an ideal platform to host the business logic of your applications. With the presentation logic handled in S3 in the form of static website hosting, and the backend taken care of by a variety of database services ranging from DynamoDB, RDS to ElastiCache; Lambda is the perfect service to run the logic of your applications as shown in the image below:
  • Real-time stream processing: When we talk about streams and AWS, only one word comes to our mind and that is Kinesis. AWS Kinesis is a powerful and scalable solution that enables you to design and develop applications that can process as well as analyze large quantities of streaming data. Mix that with Lambda and you have yourselves a variety of use cases where this design becomes applicable such as transactions processing, log analysis, social media analytics, and much more!
  • Backend services for mobile or IoT: AWS Lambda can also be used to develop and support complete backend services for your IoT as well as mobile applications. You can use this pattern in conjunction with AWS API Gateway to ...

Table of contents

  1. Title Page
  2. Copyright
  3. Credits
  4. About the Authors
  5. About the Reviewer
  6. www.PacktPub.com
  7. Customer Feedback
  8. Preface
  9. Introducing AWS Lambda
  10. Writing Lambda Functions
  11. Testing Lambda Functions
  12. Event-Driven Model
  13. Extending AWS Lambda with External Services
  14. Build and Deploy Serverless Applications with AWS Lambda
  15. Monitoring and Troubleshooting AWS Lambda
  16. Introducing the Serverless Application Framework
  17. AWS Lambda - Use Cases
  18. Next Steps with AWS Lambda