1
00:00:00,450 --> 00:00:07,590
In this video, we are going to learn how to invoke a lambda function with using the SLA.

2
00:00:08,470 --> 00:00:15,850
So basically we can invoke a lambda functions with different ways, so we can invoke directly using

3
00:00:15,870 --> 00:00:24,250
a lambda management console or we can use Lambda API or we can use a SDK or we can use a command line

4
00:00:24,250 --> 00:00:26,380
interface which is the SLA.

5
00:00:27,240 --> 00:00:29,820
So in this video we will invoke with the aid.

6
00:00:29,930 --> 00:00:37,020
Obviously, we can also configure other sources to invoke our function or we can configure Lambda to

7
00:00:37,020 --> 00:00:40,530
read from a stream or queue and invoke our function.

8
00:00:40,530 --> 00:00:43,590
We will see all these parts in the upcoming lectures.

9
00:00:45,000 --> 00:00:49,770
Before we start to invoke Lambda function, we should understand the invocation types.

10
00:00:50,160 --> 00:00:55,320
When you invoke a function, we can choose to invoke it synchronously or asynchronously.

11
00:00:55,860 --> 00:01:02,190
With synchronous invocation, we wait for the function to process the event and return the response

12
00:01:02,220 --> 00:01:08,640
with asynchronous invocation, lambda cues, the event for processing and returns the response immediately.

13
00:01:09,930 --> 00:01:16,710
So in this early section of the course, I will mainly invoke with the synchronous way to lambda function.

14
00:01:16,710 --> 00:01:22,350
But after that, in the second part of the course, we will discuss a lambda event driven architectures

15
00:01:22,350 --> 00:01:25,650
and continue with the Invoke Lambda functions asynchronously.

16
00:01:25,920 --> 00:01:30,630
Now let's focus on the synchronous invocations for the lambda functions.

17
00:01:32,280 --> 00:01:38,880
So we have already created a lambda function in the last section with using the measurement console.

18
00:01:38,970 --> 00:01:43,020
You can see in here under the lambda we have my function.

19
00:01:43,110 --> 00:01:46,170
Now it's time to invoke this lambda function with using the ADA.

20
00:01:47,550 --> 00:01:51,570
To do that, please open the pseudocode and come here.

21
00:01:51,720 --> 00:01:56,480
So we should create a new subfolder under the Section seven.

22
00:01:56,490 --> 00:02:02,430
So I'm going to choose, create the section seven and create new folder.

23
00:02:02,430 --> 00:02:03,330
Which name is.

24
00:02:04,180 --> 00:02:04,960
Lecture.

25
00:02:05,350 --> 00:02:06,310
Four, three.

26
00:02:07,060 --> 00:02:08,260
Okay, very good.

27
00:02:08,500 --> 00:02:14,740
So we basically add these similar commands in this lecture 43 folder.

28
00:02:14,740 --> 00:02:17,890
For that purpose, I'm going to copy this command text.

29
00:02:18,760 --> 00:02:21,880
And paste under the lecture portal three.

30
00:02:22,030 --> 00:02:24,160
So I'm going to change the.

31
00:02:25,170 --> 00:02:32,790
Our caption, which is the invoke lambda function using the SLA and we will follow similar commands,

32
00:02:32,790 --> 00:02:35,970
which is the lambda list function and get function.

33
00:02:36,090 --> 00:02:39,570
After that, we will invoke our function using the CLI command.

34
00:02:40,710 --> 00:02:46,380
So basically when we invoke a function synchronously, lambda runs the function and waits for a response

35
00:02:46,380 --> 00:02:47,800
when the function completes.

36
00:02:47,820 --> 00:02:52,890
Lambda returns the response from the functions code with additional data such as the version of the

37
00:02:52,890 --> 00:02:58,260
function that was invoked in order to invoke a function synchronously with the SLA command.

38
00:02:58,290 --> 00:03:00,390
We should use invoke command.

39
00:03:00,900 --> 00:03:07,350
So before proceeding to invoke command, I would like to explain that I'm writing all the commands under

40
00:03:07,350 --> 00:03:11,910
the command takes the file according to lecture number.

41
00:03:11,940 --> 00:03:20,490
So you can see in here lecture 42 and 43 has different command text files which including the related

42
00:03:21,510 --> 00:03:23,610
commands under these text files.

43
00:03:23,940 --> 00:03:25,740
So I have saved these files.

44
00:03:25,740 --> 00:03:31,080
And after that run command in our PowerShell window, I'm saving these commands into text files that

45
00:03:31,080 --> 00:03:33,870
you can copy from there and paste your command window.

46
00:03:34,200 --> 00:03:43,110
So in order to do that, let me write down our invocation command so we can come here and put this command,

47
00:03:43,110 --> 00:03:44,680
which is the invoke command.

48
00:03:44,700 --> 00:03:50,760
So as you can see that we are using the alias lambda in command and specifying function name, which

49
00:03:50,760 --> 00:03:52,650
is the main function in our case.

50
00:03:52,650 --> 00:03:56,990
And we are giving the cell binary format row in base 64 out.

51
00:03:57,970 --> 00:04:03,700
And we basically signed the payload, which is the key value pair and response back to the response

52
00:04:03,700 --> 00:04:04,630
JSON file.

53
00:04:05,050 --> 00:04:08,560
So I will use this command to invoke our function.

54
00:04:09,010 --> 00:04:12,790
In order to do that, please click the terminal and open new terminal.

55
00:04:12,880 --> 00:04:15,250
And this is starting any PowerShell.

56
00:04:15,670 --> 00:04:21,970
If you verify that you for example, you should get function, which is the my function.

57
00:04:22,210 --> 00:04:28,020
Please verify that you have this function name in your environment.

58
00:04:28,030 --> 00:04:32,070
You can see that is the get function response with encoding to all the details.

59
00:04:32,080 --> 00:04:39,850
So now I'm going to run the IMO command for this, my function for that purpose and copy this command

60
00:04:39,850 --> 00:04:45,730
and paste in here and you can see in here a lambda IMO command and giving this configuration.

61
00:04:45,820 --> 00:04:50,380
If you hit the enter you will get exception.

62
00:04:50,410 --> 00:04:51,880
What is this exception?

63
00:04:51,880 --> 00:04:54,460
Invalid request content exception.

64
00:04:54,520 --> 00:05:01,090
So when calling this IMO cooperation, you can get this exception for the could not pass request but

65
00:05:01,090 --> 00:05:02,380
into JSON file.

66
00:05:02,410 --> 00:05:10,150
So as you can see that we are passing this payload in this format, but we have to give different format

67
00:05:10,150 --> 00:05:12,620
in order to solve this exception.

68
00:05:12,640 --> 00:05:18,010
First of all, the important part is providing these command configuration.

69
00:05:18,010 --> 00:05:20,470
The CLI binary format option is required.

70
00:05:20,470 --> 00:05:27,580
If you are using the slide version two, we can also configure this option into our config file.

71
00:05:27,610 --> 00:05:34,140
But you should you should verify that these configurations should be executed in location command.

72
00:05:34,150 --> 00:05:41,470
And after that we should change this payload according to double code, another required operation.

73
00:05:41,470 --> 00:05:44,350
In my case, I need to change.

74
00:05:44,350 --> 00:05:47,160
This payload is a double code.

75
00:05:47,170 --> 00:05:49,270
You can see that we have single code.

76
00:05:49,300 --> 00:05:50,350
I'm going to.

77
00:05:51,190 --> 00:05:52,360
That's the correct one.

78
00:05:52,390 --> 00:05:58,550
You can see that key and volume information required to double code to understand the correct JSON format.

79
00:05:58,570 --> 00:06:06,370
So now I think it is okay, let's copy this command and paste again in here and hit enter.

80
00:06:07,900 --> 00:06:08,200
Okay.

81
00:06:08,200 --> 00:06:10,540
Now you should see the following output response.

82
00:06:10,540 --> 00:06:13,810
That means we have successfully invoke our lambda function.

83
00:06:13,960 --> 00:06:20,710
And you can also see that there is a response JSON generated in our main folder.

84
00:06:20,710 --> 00:06:22,300
But this should be in here.

85
00:06:22,330 --> 00:06:23,140
Okay.

86
00:06:23,410 --> 00:06:29,800
Yes, I'm moving this response station under the lecture 43 and in here you can see that such code is

87
00:06:29,800 --> 00:06:33,010
200 success and the body is the helo from lambda.

88
00:06:33,160 --> 00:06:39,460
This response file creates from the outside because we should run these commands under the.

89
00:06:40,430 --> 00:06:41,390
Lecture folders.

90
00:06:41,390 --> 00:06:49,970
You can see in here, I'm going to come section seven and you can see in here lecture 4 to 3.

91
00:06:50,000 --> 00:06:56,930
Now we should run this command under this folder to see correct response to subject.

92
00:06:56,960 --> 00:06:59,870
Okay, these are in location command and this is the response.

93
00:06:59,870 --> 00:07:03,950
So that means we have successfully run the lambda functions.

94
00:07:03,950 --> 00:07:07,160
We can also verify lambda execution from Amazon Cloud which logs?

95
00:07:07,190 --> 00:07:13,910
Let's open the function, go to function monitor and open the v logs in the cloud.

96
00:07:13,910 --> 00:07:14,450
Watch.

97
00:07:14,900 --> 00:07:23,270
And now I'm going to verify that we have invoked our function successfully in here from the cloud commands.

98
00:07:23,270 --> 00:07:24,020
Very good.

99
00:07:24,500 --> 00:07:30,140
And we can also set the multi-line character when running invoke command and command window.

100
00:07:30,170 --> 00:07:33,260
So if you come back to our we just do code.

101
00:07:34,580 --> 00:07:41,210
You can see in here under the command text, we are saving all the commands in this text file.

102
00:07:41,240 --> 00:07:45,370
Now I'm going to explain how we can make it multi-line characters.

103
00:07:45,380 --> 00:07:46,940
So for Windows.

104
00:07:48,300 --> 00:07:51,990
I'm going to add Multi-line character with this character.

105
00:07:52,140 --> 00:07:58,560
You can see in here, I can run my command with multi-line characters.

106
00:07:58,590 --> 00:08:01,170
Let's verify with the cell.

107
00:08:02,760 --> 00:08:05,460
Let me close this one and create a new terminal.

108
00:08:06,090 --> 00:08:10,590
And if you pass this command, you can see that I can make multi-line character.

109
00:08:10,710 --> 00:08:13,590
But of course, before that, I would like to.

110
00:08:14,690 --> 00:08:15,440
Locate.

111
00:08:16,260 --> 00:08:17,520
Correct folder.

112
00:08:17,580 --> 00:08:24,690
Now I'm going to run again, hit the enter and see that the status code return to 200 success.

113
00:08:24,690 --> 00:08:31,290
So that means I can invoke our lambda function with multi-line characters, but if you are using to

114
00:08:31,290 --> 00:08:34,710
make the multi-line character is differentiate.

115
00:08:34,710 --> 00:08:37,350
So that's why I'm also pasting in here.

116
00:08:38,480 --> 00:08:39,020
This.

117
00:08:39,020 --> 00:08:48,050
You can see in here, Windows is using this character and Mac is using this character to make it multi-line

118
00:08:48,050 --> 00:08:48,890
characters.

119
00:08:49,580 --> 00:08:55,220
As you can see that we have successfully invoke our lambda function and it returns 200 success and we

120
00:08:55,220 --> 00:08:59,180
have verified that this is running from our measurement console.

121
00:08:59,210 --> 00:09:02,990
In the next video we are going to invoke with passing the event JSON object.
