We're prompted to create a new lambda function and I want to do so because it's finally time to
re-run some code whenever we receive a request.
However we don't have one,
so let's first learn what lambda is before we dive into creating a function immediately.
AWS lambda that is a service which allows you to host your code on it and run it upon certain events,
this is how it looks in detail.
We get different events sources,
for example S3, this file storage service. A file upload could trigger a lambda function which then
will receive info about that file as an input and could possibly transform it.
This is useful if you have a service where people upload photos of themselves and you want to compress
them, maybe analyze them with machine learning,
you could do all that with lambda.
Another example is cloud watch,
here you can schedule events, so you can basically trigger a new lambda execution every
X minutes, hours, days, it's useful for cleanup jobs or anything which runs on a regular basis.
You can always use API Gateway to run the code whenever a request hits the API
Gateway. This of course is the interesting use case for us,
we also got other event sources but we will of course focus on the API Gateway here since this is what
we typically use in this serverless approach
when we talked about creating an API. Now this event source triggers our code next and this code is stored
in lambda and written in NodeJS, Python, Java or C#,
so PHP and so on is not supported,
you have to choose one of these languages, only these language languages run in lambda.
This code gets executed once your defined event occurs
and in this code, you can do any calculation,
reach out to other AWS services like a database to store or fetch data but any service is possible,
you could also start sending mails here and in the end, you will return a response or you will execute
a callback to indicate that this function is done, can shut down and possibly if needed, pass any data
back to the event source who called it.
This is how lambda works. In conjunction with API Gateway,
we have multiple endpoints in API Gateway,
some methods and resources and which trigger different lambda functions for each of these endpoints.
And this is exactly what we're setting up here,
so let's set it up in the next lecture.