The Comprehensive Guide to AWS Lambda Functions
Infrastructures have always been evolving since the “old days” when apps used to live on physical servers, the not-so-old days were when every app had its own virtual machine, and multiple virtual machines shared the same physical server. Recently, we had containers and each virtual machine could host several apps. But the future is serverless computing, where apps don’t even need a server to run on!
Welcome to AWS Lambda functions. You can use Lambda functions to invoke “code on demand“. Gone are the days when you had to pay for a machine that should be up 24×7 to perform tasks that take a tiny fraction of this uptime.
In this course, I assume no prior knowledge of AWS Lambda functions and take you right from the beginning in an exciting journey. In this class, we start by a little – but important – but of theory:
How to determine if your specific use case is a good candidate Lambda functions
How to write a Lambda function from scratch and configure it for optimum pricing
In this class, I intentionally give little room to theory and much more room to hands-on labs. After all, this is how you’ll work with Lambda functions afterwards, and how you’ll land your future job as an AWS cloud engineer, who is proficient in using Lambda functions. So, we start getting our hands dirty and:
Draw an overview of the main application that we’ll be using in our labs: the G2CSV. It’s a simple – but powerful – application that takes a keyword or more, searches Google for them, extracts the URLs and titles of the first-page’s results, and saves them in a CSV (Comma Separated Values) file. Pretty simple right? This app will not be running on any servers. It’ll work only using Lambda functions.
Then we explore different ways to trigger our app to work. First, using an S3 trigger, where a file upload action will invoke our app/function.
S3 is not the only valid trigger source for Lambda functions so we also explore SNS (Simple Notification Service) as an event source.
In an optional section, I take this app even one step more and add a web graphical user interface (GUI) so that the end user can type the keywords and send them. We’ll be using a combination of Lambda functions, SNS, and S3 to make it all work.
In the last part of the course, we visit CloudWatch, an integral and very powerful part of AWS. We use Lambda functions to add more detail to our regular CloudWatch events about different aspects of a running EC2 instances. Instead of just reporting a CPU spike, a Lambda function can tell you which process caused this anomaly and – optionally – take actions against it. The alert still follows its normal route through SNS, so changes should be made to how recipients get the messages.
Finally, we explore a second way of how a Lambda function could run: self-invocation. Here, we build a second app, which will be used to aggregate exchange rates hour-by-hour from an API and saves the results to an S3 bucket. This will be a demonstration on how to use Lambda functions in cron-job mode.