What is Compute
This introduction to AWS Lambda details the use of the service, and how it can help cut costs without sacrificing the resources necessary to run your code. AWS Lambda provides a scalable and highly-available serverless environment.
You will learn how to use several common languages to create advanced event-driven AWS Lambda processes. If you have knowledge of any of the supported languages, it will make development of processes much easier. These languages include the following:
Next, we will discuss how AWS Lambda can help cut costs. Aside from being serverless, Lambda charges compute power used by the nearest 100 milliseconds instead of by the hour or second, which helps immensely when running event-driven code.
Finally, we will cover AWS Lambda at a high-level. Breaking down the steps necessary to create AWS Lambda functions. These steps include selecting a blueprint from a template library or developing your own, choosing the event triggers, uploading your code and defining the configuration details (required resources, maximum execution timeout, IAM role, handler name, trigger definition), and lastly, compiling all the information to finalize the development.
Resources referenced within this lecture:
Hello and welcome to this lecture where we shall take an introductory look at AWS Lambda.
The first point to make about AWS Lambda is that it's a service that lets you run your own code in response to events in a scalable and highly available serverless environment but what does serverless mean?
Essentially serverless means that you do not need to worry about provisioning and managing your own compute resource to run your own code. Instead, this is managed and provisioned by AWS. AWS will start, scale, maintain, and stop the compute resources required for as long as you need them, which can be as short as a few milliseconds depending on your Lambda function.
I'll cover more Lambda functions as we go through this lecture.
Although it's named serverless, it does of course require servers or at least computer power to carry out your code requests but because the AWS user does not need to be concerned with what compute power is used or where it comes from, it's considered serverless from the user perspective.
More information on serverless computing can be found within our existing course 'What is Serverless Computing' within the 'Getting Started with Serverless Computing' learning path.
Now we have a high level overview of what AWS Lambda is. Let's look at what it can be used for. AWS Lambda is great for a number of different use cases when you need to run and execute code in response to event-driven triggers. This makes it easy to build applications that will respond quickly to new information in addition to automating processes in existing applications and services.
For example, you could create a Lambda function to execute every time an image is uploaded to a particular bucket in S3, which will then compress the image into a zip format. This function will be triggered upon a PUT request to the bucket.
If you are proficient in writing in any of the supported languages of Lambda, which at the time of writing this course are Node.js, Java, C#, and Python, then you can create advanced event-driven processes within your environment. If you'd like additional examples and use cases of AWS Lambda, please take a look at the link on the screen.
One big difference between the compute power used for Lambda, and that of EC2, for example, is that with EC2, you are charged for that compute power by the hour or by the second, depending on the AMI. However, with AWS Lambda, you are only charged for the compute time used to the closest 100 milliseconds plus the number of request triggered by your function making this a very cheap compute option for running event-driven code.
Now let's take a look at how we can configure this service and understand some of the components, which will allow us to get a better understanding of how it works. For example, how AWS Lambda knows what compute resource it should use.
Let's start by defining what a Lambda function is. A Lambda function contains your code that you have written to perform the required task plus any dependencies for that code. In addition to this, the function also includes a number of configurational details, which are defined when a Lambda function is created.
- The required resources. The required resources provides just that, the resources that are required to carry out the execution of the code, however, the only input we have is to specify the amount of RAM required. The compute power is then determined by AWS Lambda using a ratio related to the amount of RAM specified.
- Maximum execution timeout, this specifies the maximum amount of time the Lambda function will run before it's terminated.
- IAM role, this grants the Lambda the appropriate permissions to carry out the execution of the code.
- Handler name, this refers to the method in your code where the execution of the function starts. When the function is triggered, any event information is passed as a parameter to the handler method.
- There is another key element of AWS Lambda, and that is defining the trigger that invokes the AWS Lambda function itself.
When creating a new Lambda function via the AWS Management Console, you are asked to define the trigger prior to either uploading or creating your code for the function. These triggers or event resources can be via another AWS service such as S3, DynamoDB, CloudFront, or by invoking the function on demand.
For a full list of event-driven resources, please see the following link.
At a high level, the configuration steps for creating an AWS Lambda function via the AWS Management Console is as follows. Firstly, select a blueprint. AWS Lambda provides a large number of common blueprint templates, which are preconfigured Lambda functions. To save time on your own code, you can select one of these blueprints, and then customize it as necessary. An example of one of these blueprints is S3-get-object, an Amazon S3 trigger that retrieves metadata for the object that is being updated.
Next, configure triggers. As I just explained, you are asked to define the trigger for the Lambda function. Using an example from step one, you would be required to answer a number of configurational questions relating to S3 such as specifying which S3 bucket the function will run on.
Configure the function, this section requires you to either upload your code or edit in line. This section also requires you to define the required resource, maximum execution timeout, the IAM role, and the handler name.
Once all this information has been entered, your AWS Lambda function has been created. The key benefit of using AWS Lambda is that it is a highly scalable serverless service coupled with fantastic cost optimization compared to EC2 as you are only charged for compute power whilst the code is running and for the number of functions called.
For your own hands-on experience with AWS Lambda, take a look at our labs, which will guide you through how to create your first Lambda function: Introduction to AWS Lambda, Automating EBS Snapshots with AWS Lambda, and Process Amazon S3 Events with AWS Lambda.
That now brings us to the end of this lecture covering AWS Lambda. Coming up in the next lecture, I shall discuss AWS batch.
Stuart has been working within the IT industry for two decades covering a huge range of topic areas and technologies, from data center and network infrastructure design, to cloud architecture and implementation.
To date, Stuart has created 90+ courses relating to Cloud reaching over 140,000 students, mostly within the AWS category and with a heavy focus on security and compliance.
Stuart is a member of the AWS Community Builders Program for his contributions towards AWS.
He is AWS certified and accredited in addition to being a published author covering topics across the AWS landscape.
In January 2016 Stuart was awarded ‘Expert of the Year Award 2015’ from Experts Exchange for his knowledge share within cloud services to the community.
Stuart enjoys writing about cloud technologies and you will find many of his articles within our blog pages.