1
00:00:02,640 --> 00:00:07,820
We're prompted to create a new lambda function and I want to do so because it's finally time to

2
00:00:07,910 --> 00:00:11,000
re-run some code whenever we receive a request.

3
00:00:11,000 --> 00:00:13,580
However we don't have one,

4
00:00:13,610 --> 00:00:18,530
so let's first learn what lambda is before we dive into creating a function immediately.

5
00:00:18,800 --> 00:00:26,090
AWS lambda that is a service which allows you to host your code on it and run it upon certain events,

6
00:00:26,090 --> 00:00:27,760
this is how it looks in detail.

7
00:00:28,040 --> 00:00:29,840
We get different events sources,

8
00:00:29,900 --> 00:00:38,360
for example S3, this file storage service. A file upload could trigger a lambda function which then

9
00:00:38,360 --> 00:00:43,580
will receive info about that file as an input and could possibly transform it.

10
00:00:43,580 --> 00:00:49,490
This is useful if you have a service where people upload photos of themselves and you want to compress

11
00:00:49,490 --> 00:00:52,360
them, maybe analyze them with machine learning,

12
00:00:52,400 --> 00:00:54,920
you could do all that with lambda.

13
00:00:54,920 --> 00:00:57,100
Another example is cloud watch,

14
00:00:57,230 --> 00:01:04,610
here you can schedule events, so you can basically trigger a new lambda execution every

15
00:01:04,610 --> 00:01:12,050
X minutes, hours, days, it's useful for cleanup jobs or anything which runs on a regular basis.

16
00:01:12,050 --> 00:01:18,490
You can always use API Gateway to run the code whenever a request hits the API

17
00:01:18,500 --> 00:01:22,570
Gateway. This of course is the interesting use case for us,

18
00:01:22,760 --> 00:01:28,070
we also got other event sources but we will of course focus on the API Gateway here since this is what

19
00:01:28,070 --> 00:01:30,690
we typically use in this serverless approach

20
00:01:30,770 --> 00:01:39,800
when we talked about creating an API. Now this event source triggers our code next and this code is stored

21
00:01:39,800 --> 00:01:45,130
in lambda and written in NodeJS, Python, Java or C#,

22
00:01:45,140 --> 00:01:47,170
so PHP and so on is not supported,

23
00:01:47,270 --> 00:01:52,940
you have to choose one of these languages, only these language languages run in lambda.

24
00:01:52,940 --> 00:01:56,760
This code gets executed once your defined event occurs

25
00:01:57,020 --> 00:01:59,690
and in this code, you can do any calculation,

26
00:01:59,690 --> 00:02:06,430
reach out to other AWS services like a database to store or fetch data but any service is possible,

27
00:02:06,440 --> 00:02:13,430
you could also start sending mails here and in the end, you will return a response or you will execute

28
00:02:13,430 --> 00:02:21,380
a callback to indicate that this function is done, can shut down and possibly if needed, pass any data

29
00:02:21,410 --> 00:02:24,150
back to the event source who called it.

30
00:02:24,550 --> 00:02:29,230
This is how lambda works. In conjunction with API Gateway,

31
00:02:29,510 --> 00:02:33,120
we have multiple endpoints in API Gateway,

32
00:02:33,170 --> 00:02:39,250
some methods and resources and which trigger different lambda functions for each of these endpoints.

33
00:02:39,290 --> 00:02:41,390
And this is exactly what we're setting up here,

34
00:02:41,480 --> 00:02:43,570
so let's set it up in the next lecture.
