1
00:00:00,690 --> 00:00:05,250
In this video, we are going to see how to recruit our lambda functions.

2
00:00:05,280 --> 00:00:09,150
That means you will see a Lambda Invocation types.

3
00:00:09,750 --> 00:00:15,180
After that, we will map these Lambda Invocation types with our course one developing serverless e-commerce

4
00:00:15,180 --> 00:00:15,960
application.

5
00:00:16,200 --> 00:00:22,860
So this Lambda Invocation types will be our serverless journey when developing our service ecommerce

6
00:00:22,860 --> 00:00:23,610
application.

7
00:00:25,330 --> 00:00:29,900
So Islam, the function is using a river for various use cases.

8
00:00:29,920 --> 00:00:37,990
Sometimes we want to invoke lambda function over HTTP and other times trigger a function based on different

9
00:00:37,990 --> 00:00:38,710
events.

10
00:00:39,570 --> 00:00:45,420
It is extremely useful to understand the different ways that we can invoke lambda function.

11
00:00:46,140 --> 00:00:50,040
Here are three different ways we can invoke lambda functions.

12
00:00:50,700 --> 00:00:54,600
You can see in here a place Lambda has three invocation types.

13
00:00:55,050 --> 00:00:57,150
Lambda Synchronous Invocation.

14
00:00:57,150 --> 00:00:59,430
Lambda Asynchronous Invocation.

15
00:00:59,490 --> 00:01:03,240
Lambda Event Source Mapping with Pulling Invocation.

16
00:01:05,000 --> 00:01:08,630
So you can all see in location types in one image.

17
00:01:08,780 --> 00:01:14,960
Synchronous invocation is triggered by push model and execute immediately and wait response.

18
00:01:14,990 --> 00:01:17,600
We can say request response model.

19
00:01:18,510 --> 00:01:23,080
Asynchronous invocation is triggered by event model and executes.

20
00:01:23,100 --> 00:01:23,990
Asynchronous.

21
00:01:24,000 --> 00:01:24,810
Don't wait.

22
00:01:24,810 --> 00:01:26,130
Immediate response.

23
00:01:26,760 --> 00:01:30,270
Event source mapping invocation is triggered by pol based.

24
00:01:30,300 --> 00:01:33,900
That means lambda function receive multiple items.

25
00:01:35,520 --> 00:01:39,810
So let's see one by one and explain these types.

26
00:01:40,470 --> 00:01:42,780
Lambda Synchronous invocation.

27
00:01:42,930 --> 00:01:47,490
This is one of the simple Lambda Invocation model in this communication type.

28
00:01:47,520 --> 00:01:53,610
Lambda functions execute immediately when you perform the Lambda Invoke by API call.

29
00:01:53,820 --> 00:02:00,990
So when we perform a Lambda Invoke an API call, we wait for the function to process the function and

30
00:02:00,990 --> 00:02:02,640
return back to the response.

31
00:02:03,060 --> 00:02:08,580
The response data includes the function response and additional data which can be retrieved from the

32
00:02:08,580 --> 00:02:11,540
Dynamo DB or some other resources.

33
00:02:11,700 --> 00:02:13,920
But the idea is we should wait.

34
00:02:13,920 --> 00:02:16,470
A response from the Synchronous Invocation.

35
00:02:18,060 --> 00:02:25,160
A common scenario for synchronous invocation is the API Gateway, Lambda and Dynamo DB integration.

36
00:02:25,170 --> 00:02:31,590
You can see in the Image API Gateway Lambda and Dynamo DB that we can perform CRUD operation for a particular

37
00:02:31,590 --> 00:02:35,910
Dynamo DB table with exposing APIs from the API gateway.

38
00:02:36,880 --> 00:02:42,760
The important thing is in here, the invocation type flag should be request response.

39
00:02:43,480 --> 00:02:50,020
This instructs a place to execute our lambda function and wait for the response or function to complete.

40
00:02:50,650 --> 00:02:57,580
When we perform the synchronous invocation, we are responsible for inspecting the response and determining

41
00:02:57,580 --> 00:03:02,410
if there was an error like time or execution and decide to retry invocation.

42
00:03:03,330 --> 00:03:10,440
We can perform synchronous requests most in location using a double CLI SDK and many other options.

43
00:03:11,370 --> 00:03:19,170
You can see an example of synchronous invocation using a double c that we are running the lambda invoke

44
00:03:19,230 --> 00:03:21,390
comments on cli.

45
00:03:21,810 --> 00:03:28,230
As you can see that when we specify the invocation type like is request response, that means it will

46
00:03:28,470 --> 00:03:34,770
execute our function and wait for the function response in order to complete and return response.

47
00:03:35,190 --> 00:03:41,400
The important part is we are responsible for checking the request, checking the response and determining

48
00:03:41,400 --> 00:03:44,280
whether it is an error or we should try the invoke.

49
00:03:44,520 --> 00:03:50,430
So in this synchronous invocation, we are waiting response and according to this response, we are

50
00:03:50,430 --> 00:03:55,320
checking the response data and it is looking for it is getting error or not.

51
00:03:55,320 --> 00:03:59,310
If it is getting error, we are going to retry the invoke again.

52
00:04:01,020 --> 00:04:07,590
There are many services that can trigger lambda function synchronously here, some of them in here.

53
00:04:07,590 --> 00:04:14,010
You can see that application load will answer Amazon Incognito, Amazon, Lakes, Alexa API, Gateway

54
00:04:14,010 --> 00:04:17,910
Cloud, Front Kinesis Data streams and so on.

55
00:04:20,380 --> 00:04:25,240
So now the second invocation type is Lambda Asynchronous invocation.

56
00:04:25,780 --> 00:04:31,900
In this communication type, Lambda function works with the events and invoke by events and not respond

57
00:04:31,900 --> 00:04:32,860
immediately.

58
00:04:33,520 --> 00:04:37,300
Basically, we can invoke a lambda function asynchronously.

59
00:04:37,480 --> 00:04:45,370
After that, Lambda sends the event an internal queue and returns a success response without any additional

60
00:04:45,370 --> 00:04:46,240
information.

61
00:04:46,840 --> 00:04:53,530
After that, a separate process reads the events from the queue and runs our lambda function.

62
00:04:54,450 --> 00:05:01,920
So you can see a common scenario for asynchronous invocation is the S3 Lambda and dynamic DB.

63
00:05:02,160 --> 00:05:13,820
You can see in the Image S3 or Amazon sense a sense trigger an event and this will be triggered a number

64
00:05:13,830 --> 00:05:19,800
asynchronously and a double is lambda interact with the dynamo db in the diagram Amazon S3 will call

65
00:05:19,820 --> 00:05:25,320
the Lambda asynchronously when a new object is written into the bucket.

66
00:05:25,950 --> 00:05:30,270
Amazon S3 has several events that can trigger to a lambda.

67
00:05:30,390 --> 00:05:36,210
For example, we can set that a new object is uploading the into bucket.

68
00:05:36,210 --> 00:05:41,580
We can trigger an event today lambda that is executed lambda function asynchronously.

69
00:05:43,110 --> 00:05:48,630
In order to invoke a function asynchronously, we should set the invocation type parameter to event.

70
00:05:48,930 --> 00:05:56,530
So it is very important you can see an example of the asynchronous invokes using the SLA.

71
00:05:57,000 --> 00:06:02,640
We can see that we are running a double lambda invoke comment and the invocation type is event.

72
00:06:02,760 --> 00:06:07,140
When we specify the invocation type, parameter value is event.

73
00:06:07,380 --> 00:06:14,190
If the function failed a the will automatically retry the invoke device because in asynchronous communication

74
00:06:14,370 --> 00:06:23,790
the lambda is automatically triggered by the triggered invoke by twice when there is an error by default.

75
00:06:23,790 --> 00:06:27,570
A double is lambda sets a retry policy for asynchronous invocations.

76
00:06:27,570 --> 00:06:35,130
Your function will be invoked twice if there is an error in order to avoid event losses when using asynchronous

77
00:06:35,130 --> 00:06:42,150
lambda, always attach a dead letter Q on the function in order to save events that weren't successfully

78
00:06:42,150 --> 00:06:42,870
processed.

79
00:06:43,840 --> 00:06:50,680
Here you can list of the services that invoke Lambda function asynchronously as you set that Amazon

80
00:06:50,680 --> 00:06:51,790
S3 event.

81
00:06:52,360 --> 00:06:58,900
SNS S is cloud formation, cloud watch looks and Events Code Command, pull, based, invokes and so

82
00:06:58,900 --> 00:06:59,230
on.

83
00:07:01,440 --> 00:07:07,470
So if you come to the last location type, which is the event source mapping with polling location,

84
00:07:08,070 --> 00:07:14,670
this is the poll based location model allows us to integrate with the police streams and queue based

85
00:07:14,670 --> 00:07:15,570
services.

86
00:07:16,230 --> 00:07:20,190
These services don't invoke a lambda function directly.

87
00:07:20,820 --> 00:07:29,550
Lambda will pull from the available case or kinesis streams, retrieve records and invoke the functions.

88
00:07:30,520 --> 00:07:37,030
A.W. Islam the event source mapping manage the polar and performs the synchronous inverse of our function.

89
00:07:37,780 --> 00:07:41,470
Data streams or cues are read in the batch.

90
00:07:41,740 --> 00:07:48,280
The function receives multiple items when executing to function, so a batch size can configure according

91
00:07:48,280 --> 00:07:49,480
to the service type.

92
00:07:49,480 --> 00:07:54,070
And after that, the event source mapping will send data according to batch size.

93
00:07:54,550 --> 00:08:01,990
If the batch size is too large to send in one event, it has to be split up, resulting in events with

94
00:08:01,990 --> 00:08:04,870
smaller number of items than the batch size.

95
00:08:05,980 --> 00:08:12,100
So you can see in the image a common scenario for event source mapping with polling location is the

96
00:08:12,520 --> 00:08:21,910
case and a lambda you can see in the image Amazon case and lambda using the event source mapping, basically

97
00:08:21,910 --> 00:08:26,380
lambda function pulling events from the case.

98
00:08:26,410 --> 00:08:30,340
Let me explain more clearly in this diagram.

99
00:08:30,340 --> 00:08:33,070
Amazon case has some key records.

100
00:08:33,070 --> 00:08:38,620
These records can be added from other services like event, SMS and so on.

101
00:08:38,620 --> 00:08:44,500
So the idea is that we have some Q message in the Amazon queue.

102
00:08:45,130 --> 00:08:53,890
After that, a lambda function, pull the events from the Amazon case and receive Q records with event

103
00:08:53,890 --> 00:08:55,450
source mapping invocation.

104
00:08:55,780 --> 00:09:02,440
So Lambda function retrieve Q records according to the batch size property of polling configuration.

105
00:09:03,220 --> 00:09:09,280
Another common scenario for one source mapping with polling location is string based processing.

106
00:09:09,640 --> 00:09:16,480
These are the Kinesis and Dynamo DC streams that can learn the pole the stream records with event source

107
00:09:16,480 --> 00:09:17,890
mapping in locations.

108
00:09:18,880 --> 00:09:21,370
So the base size property is very important.

109
00:09:21,370 --> 00:09:28,180
We give the example of the x and lambda and we said that the stream based processing by A.B. streams

110
00:09:28,180 --> 00:09:33,430
and kindness streams using the event based event source mapping location.

111
00:09:33,640 --> 00:09:39,640
And here is the list of the services that invoke Lambda functions as an event source mapping.

112
00:09:39,670 --> 00:09:45,610
These are the Amazon Kinesis, Amazon Dynamo DB and Amazon Simple Q Services.

113
00:09:47,540 --> 00:09:52,100
As you can see that we have seen several a number in location types.
