Getting started with Lambda
Practical Usage of Lambda
Executing code in response to specific event triggers is a common need. In fact, Event-Driven Programming has long been an important approach in Software Development. So if trigger response is useful within an operating system, why not for cloud-based web applications? To answer precisely that need, Amazon recently released Lambda. Lambda will launch AWS resources and execute snippets of code in response to predefined events, automating the management of all of necessary underlying infrastructure...and at a ridiculously low price.
In this course you'll get complete introduction to AWS Lambda. Lambda is not a particularly complex service, but setting IAM roles and security groups might be tricky. This tutorial, written by our expert Cloud Solutions Architect Kevin Felichko, will help you understand how to get started, and will also show you an interesting and practical use-case.
Who should take this course
If you want to learn more about the AWS services being discussed here, check out our other AWS courses. Also, our Lambda quiz questions can serve as a nice follow up. You will be tested on what you learnt in this video, but will also learn more at the same time thanks to the documentation associated with each question.
Do you have questions on this course? Contact our cloud experts in our community forum.
CloudWatch is a service that is used to monitor the operation and performance of an AWS environment. With Lambda we can use the log stream functionality of CloudWatch to monitor the execution of a function.
Lambda includes a set of metrics we can used to monitor the overall statistics of our functions, with CloudWatch log streams we can get insight into the execution of our functions by using console.log. Each console.log message will be written out to the log stream meaning we can add messages that indicate where we are in the code. We can output the values of variables to see their state at any point during the execution. In the event of an error we can see what happen and the structures behind it. Each execution of the function writes a minimum of three messages in the log stream. The start of the execution is logged along with the time it was launched in a unique identifier called the request ID. The end of the execution is logged and it contains the request ID along with the time the execution completed.lastly, there's a report message that indicates the duration of the execution, the milliseconds that will be build the memory allocated and the memory used during the execution of the function.
If we do nothing else and the execution succeeds, this is all we will have in the log steam. If the execution fails there will be an error message included in two messages. One that indicates the task failure with the full stack trace and another that summarizes the error message.
Our test run of the S3 rest run application shows the standard messages along with some informational output we thought was important to include. If there was an error during execution or the function did not do what we expected, these messages can help. When we upload a none JSON file to the S3 bucket or informational messages give us a peek into what happened. The first two informational messages rewrite are the S3 bucket and the name of the file. After these messages are written to the log stream an error occurs.
Combining these messages and the error stack trace can help us track down what went wrong. It would be unfavorable to have a stack trace in production but no additional information that can pinpoint the problem to be fixed. CloudWatch metrics we can get from Lambda include the request account, error count and latency.
The request account tells us how many times the function was executed, the error count metric tells us how many of those executions did not succeed, latency gives us insight into the time it takes in milliseconds for an execution to start after it has been invoked. Like other CloudWatch metrics we can create alarms such as sending a notification when the error count exceeds say 10 in a 5-minute window. As we have seen in this course Lambda is an impressive service, even in preview mode the functionality is robust and very useful. We should expect many updates as AWS improves the service and listens to feedback from its customers.
Cloud economy will be here to help you navigate these improvements for both Lambda and many other Cloud based services. Be sure to check out our other courses and participate in our Cloud community.
About the Author
Kevin is a seasoned technologist with 15+ years experience mostly in software development.Recently, he has led several migrations from traditional data centers to AWS resulting in over $100K a year in savings. His new projects take advantage of cloud computing from the start which enables a faster time to market.
He enjoys sharing his experience and knowledge with others while constantly learning new things. He has been building elegant, high-performing software across many industries since high school. He currently writes apps in node.js and iOS apps in Objective C and designs complex architectures for AWS deployments.
Kevin currently serves as Chief Technology Officer for PropertyRoom.com, where he leads a small, agile team.