- Now let's review an introduction to AWS Lambda.
With AWS Lambda we gain access to serverless computing,
now of course serverless is a hot topic these days
and let's keep in mind that there's much more
to serverless than just Lambda.
Lambda is just one small part of the serverless
sort of movement and Lambda would give us
what we might call functions as a service
and so by serverless, what we mean is that
even though we know somewhere out there
in an AWS data center, we know that
there is a server running this code,
from our perspective as a customer,
as an organization, there is no server for us to manage.
We're just writing code and allowing AWS
to essentially execute that code.
And so, Lambda is great for all kinds
of different use cases.
We could run scheduled tasks, microservices,
event handlers, all kinds of different things
we can run on AWS Lambda.
Anything that can be decomposed
into small targeted functions,
could be written to use Lambda.
Now, one of the things that I'd like
to point out is that I see a lot of folks
coming to Lambda, or coming to AWS looking to use Lambda,
but still in a mindset of like traditional
enterprise computing where you're creating
these very large applications.
Right so, we're not going to take
this large enterprise java application
comprised of thousands of functions
across hundreds of classes and objects,
and squeeze that into Lambda.
That's not what we're talking about.
With Lambda, we create functions
and we call them functions because
that's what they are.
Just like we might write
a piece of software is a collection
of functions or classes and objects,
the same is true with Lambda.
So we might decompose those enterprise applications
into various functions and then our software
becomes a collection of functions.
And so, with Lambda,
we pay for compute time per 100 milliseconds.
Now of course the more memory we use,
the more we pay, so there is a relationship
between the amount of memory that we use
and the length of time that an application runs for.
So, we can create functions in several different ways.
We can use the inline editor which
is available to us in the AWS console,
and by using the inline editor
we have a pretty quick and easy way
of writing out a particular function.
But probably the more common way
is to upload a zip file and so,
If our function needs say, other dependencies,
other packages, then those need to be included
with our code and the only way
to do that is by uploading a zip file.
And so with Lambda, once we create a function,
we then invoke those functions
and we can invoke them programmatically
or even manually through the CLI tools or the SDK,
or perhaps the most common way
and perhaps one of the most powerful ways,
is to leverage events.
Events can come from all kinds
of different places within AWS.
A classic example of an event might be,
to leverage Amazon S3 event notifications.
So with S3, we have a bucket that we can store
objects in, and we'll talk more about S3 later on,
but as we upload things to that bucket,
that would be an event.
As we delete something, that would be an event.
And so whatever is happening in that bucket,
those events can each be used
to trigger Lambda functions in response,
and the Lambda function could then
retrieve that data from s3 and go on
to perform some type of processing.
And once these functions are invoked
and they start to execute, AWS handles
all of the underlying infrastructure.
Again, we know that there's a server somewhere,
that is actually executing, you know,
the CPU cycle is responsible for making our function work,
but we don't have to manage it.
AWS manages that actual underlying machines.
AWS handles the deployment of our code,
and so getting our code to that machine
in order to be executed, Amazon handles that.
And Amazon handles the scaling,
We could invoke, one function, one time.
we could invoke two functions,
each of them thousands of times, right?
So we could have, the default soft limit
for Lambda is 1000 concurrent executions, right?
And If you were to lift that, to say,
two or three or four thousand concurrent executions,
AWS will handle and do all that's necessary
to handle the scaling, to make that happen.
And so here in this particular example,
we have a piece of Python code,
a short piece of Python code that,
we might write to be, let's say,
a Hello, World! or a simple example of a Lambda function.
And within there, I just wanted to point out,
that within that code you can see
that we are defining a handler, right?
That's a function and we need to tell
the Lambda service, the name of that
handler function and that handler receives
a couple of different arguments,
in this case, event and context
and that's how our Lambda function
can receive data in order to do it's processing
and how using the context parameter
is how we can communicate back
to the Lambda service that our function
was either successful or our function failed.
And so, we take our code and we give our code
to the Lambda service and in doing so
we specify the run time,
be it Python, Node.js, Java or C#,
we specify the memory that we might need,
anywhere from 128 megs all the way up to three gigs,
and we also specify the execution timeout,
anywhere from a few seconds all the way up
to 300 seconds or five minutes.
So that's another thing to keep in mind
that Lambda does have those limitations,
up to three gigs of memory,
up to five minutes of execution time.
So, if your application needs more memory or more time,
then Lambda is probably not an option.
Once we have our code, we have our run time,
memory limit and execution timeout set,
that gives us a Lambda function.
We can then invoke that Lambda function.
Again, either programmatically, manually or through events.
And we can invoke that function
pretty much as many times as we want.
And Amazon, every time it's invoked,
Amazon handles the deployment of our code,
the execution of the code and the collection of logs,
and we're gonna talk about log collection later on,
but in this scenario with AWS Lambda,
the beautiful thing is that,
all we have to do is write code.
Give the code to AWS, configure a few things,
and then allow AWS to handle the rest.