1
00:00:00,240 --> 00:00:08,760
In this video, we are going to update a lambda function with additional dependencies using a cli.

2
00:00:10,100 --> 00:00:15,590
In the last video, we have already the update on the function quote, but this time we will update

3
00:00:15,590 --> 00:00:16,870
with dependencies.

4
00:00:16,880 --> 00:00:22,640
We didn't add any dependencies into our Node.js lambda function yet, so let's see how we can manage

5
00:00:22,640 --> 00:00:23,030
it.

6
00:00:24,310 --> 00:00:31,720
If our lambda function depends on libraries other than the SDK for JavaScript, we can use MPM to include

7
00:00:31,720 --> 00:00:33,400
them in our deployment package.

8
00:00:33,430 --> 00:00:38,860
We should ensure that the Node.js version in our local environment makes the Node.js version of our

9
00:00:38,860 --> 00:00:39,490
function.

10
00:00:39,910 --> 00:00:46,090
So basically we will use NPM package management tool for installing dependencies in our Node.js lambda

11
00:00:46,090 --> 00:00:48,940
function and deploy with these dependencies.

12
00:00:49,300 --> 00:00:56,170
As we know that in Node.js application, once we add any external package with using the NPM install

13
00:00:56,170 --> 00:01:04,000
command, this will create package that JSON file and note modules folder in order to store these external

14
00:01:04,000 --> 00:01:05,370
library resources.

15
00:01:05,380 --> 00:01:10,960
So that means we should zip all these files when deploying lambda function to the lambda.

16
00:01:12,400 --> 00:01:16,840
Let's write down step by step what we are going to do in this video.

17
00:01:16,990 --> 00:01:20,830
We will install required dependencies into node modules folder.

18
00:01:21,400 --> 00:01:25,960
After that, we will zip function code update function code with the CLI.

19
00:01:25,960 --> 00:01:30,370
And lastly, we will invoke updated lambda function with using SQL Command.

20
00:01:30,670 --> 00:01:37,240
So we have already created my function to and quotes are stored, which is coming from the last section

21
00:01:37,240 --> 00:01:39,130
into the index JS file.

22
00:01:39,310 --> 00:01:46,870
If you can open the we just read your code, you can see in here we will follow this step and we have

23
00:01:46,870 --> 00:01:50,320
deployed my function to with this index CSS code.

24
00:01:50,410 --> 00:01:57,310
Now we can install libraries in the node modules directory using the NPM install command.

25
00:01:57,310 --> 00:02:06,100
So we can think that in this lecture 53 folder, this is the lambda function code and dependencies should

26
00:02:06,100 --> 00:02:09,550
be it should be included under the this folder name.

27
00:02:09,550 --> 00:02:16,240
And we can think that this lecture folder is our lambda function folder and we use Node.js runtime.

28
00:02:16,240 --> 00:02:22,600
So you can think these are Node.js folder of projects which including indexes package JSON file and

29
00:02:22,600 --> 00:02:25,510
node modules folders which including the dependencies.

30
00:02:25,900 --> 00:02:27,770
Okay, let's get started.

31
00:02:27,790 --> 00:02:33,940
If you come to command JS, we will start with the install required dependent dependencies into our

32
00:02:33,940 --> 00:02:34,870
function folder.

33
00:02:35,680 --> 00:02:46,330
So I'm going to install some of the kits, which is the x ray SDK package, which is for the tracing

34
00:02:46,330 --> 00:02:47,800
or invocations.

35
00:02:47,800 --> 00:02:55,090
But I'm using this package for an example and show how we can use dependencies in the lambda functions.

36
00:02:55,090 --> 00:03:01,930
So please copy this command and locate the folder lecture 53 and paste this command into the PowerShell

37
00:03:01,930 --> 00:03:04,360
or your command line and hit enter.

38
00:03:04,360 --> 00:03:10,840
So this creates a folder structure that's similar to our Node.js applications.

39
00:03:10,840 --> 00:03:18,970
You can see that under the lecture 53, we will have no notice and now it is creating package JSON file.

40
00:03:18,970 --> 00:03:23,920
So these three files are created from our NPM install command.

41
00:03:23,920 --> 00:03:28,420
And this folder is because Node.js function and Node.js project.

42
00:03:28,420 --> 00:03:31,450
So see that no modules added the x ray package.

43
00:03:31,450 --> 00:03:35,260
If you come here you can see the x ray package and required package in here.

44
00:03:35,500 --> 00:03:41,980
And if you also check the package JSON file, you can see that there is a dependencies which is a x

45
00:03:42,160 --> 00:03:42,730
SDK.

46
00:03:42,730 --> 00:03:44,590
And here is the version number.

47
00:03:44,830 --> 00:03:45,400
Okay.

48
00:03:45,430 --> 00:03:46,180
Very good.

49
00:03:46,210 --> 00:03:53,830
Now the second step is if you follow the second step, the second step is a function zip to function

50
00:03:53,830 --> 00:03:55,240
quote, zip archive.

51
00:03:55,270 --> 00:04:00,370
So if you scroll down and see the follow the second step, we have several options.

52
00:04:00,370 --> 00:04:07,990
You can see in here in the Windows Manual this time I have to follow the manual version because this

53
00:04:07,990 --> 00:04:08,650
is important.

54
00:04:08,650 --> 00:04:13,750
We should follow the manual zip dependencies cannot be moved we to compress command.

55
00:04:13,780 --> 00:04:19,810
This command is not working for the archiving all the normal dos and under these packages.

56
00:04:19,810 --> 00:04:22,360
So that's why I have to follow manual way.

57
00:04:23,050 --> 00:04:28,810
You can also follow zip command from the Mac users, but Windows users, the compressed archive is not

58
00:04:28,810 --> 00:04:31,620
working, so that's why we should follow the manually.

59
00:04:31,630 --> 00:04:32,170
Zip.

60
00:04:32,170 --> 00:04:34,300
This folder is a function.

61
00:04:35,110 --> 00:04:36,790
So select indexes.

62
00:04:37,520 --> 00:04:40,490
And package JSON files and Node.js modules.

63
00:04:40,520 --> 00:04:49,850
And we will zip this file with our application when we are making zip file of these indexes and package

64
00:04:49,850 --> 00:04:50,850
JSON files.

65
00:04:50,870 --> 00:04:58,430
The important thing is you shouldn't have subfolder into the function zip file when extracting.

66
00:04:58,430 --> 00:05:01,660
It should have these files as expected.

67
00:05:01,670 --> 00:05:04,020
So let me show how we can do that.

68
00:05:04,040 --> 00:05:08,420
So for example, right click and go to the indexes.

69
00:05:08,450 --> 00:05:19,100
Now I'm going to select this file's indexed JS package JSON files anomalous right click sent to compressed

70
00:05:19,130 --> 00:05:20,120
zip folder.

71
00:05:21,740 --> 00:05:22,270
Okay.

72
00:05:22,280 --> 00:05:24,170
This will be the function.

73
00:05:25,560 --> 00:05:26,310
Zip file.

74
00:05:27,510 --> 00:05:36,000
If you double click this function as you can see that these folders has now any folder folders are directly.

75
00:05:36,000 --> 00:05:43,380
You can see under the zip file indexes package JSON and this should be located in the root folder structure.

76
00:05:43,380 --> 00:05:49,410
So this is important when you are zipping an archiving or Node.js, lambda functions.

77
00:05:49,830 --> 00:05:57,390
Okay, now we have finished the second step, but before update the function code, let's check our

78
00:05:57,390 --> 00:05:59,610
existing code on the mission console.

79
00:05:59,640 --> 00:06:05,910
If you go to lambda function, if you come to my function to uncheck the code, this is the our latest

80
00:06:05,910 --> 00:06:08,490
code and there is only one index case file.

81
00:06:08,640 --> 00:06:13,980
But when we are updating this code we should see the package Jasons and Node.js modules in here.

82
00:06:13,980 --> 00:06:18,090
So that means we will update the code with additional dependencies.

83
00:06:18,390 --> 00:06:25,890
Okay, let's come back to our we used to do code and now I'm going to go to the third step, come to

84
00:06:25,890 --> 00:06:30,240
command text and see the third step, which is the update function code.

85
00:06:30,270 --> 00:06:36,480
In order to update function code, you can see in here we will use update function called select command.

86
00:06:36,510 --> 00:06:42,060
Passing the function name and zip file is you remember that we have a function, that zip file which

87
00:06:42,060 --> 00:06:47,010
includes the all required index and package files in here.

88
00:06:47,010 --> 00:06:53,490
So that's why we can easily update our code, copy this command and paste into the your command window

89
00:06:53,490 --> 00:06:54,930
and hit enter.

90
00:06:56,640 --> 00:06:59,790
So this will be update our code with additional dependencies.

91
00:06:59,790 --> 00:07:05,700
Yes, you can see that there is a success response, including the function definitions.

92
00:07:05,700 --> 00:07:13,590
And if you go back to the our management console and if you refresh this page, we will see that our

93
00:07:13,590 --> 00:07:16,680
function will be updated with the Node.js modules.

94
00:07:16,680 --> 00:07:17,500
Okay.

95
00:07:17,850 --> 00:07:23,400
As you can see, that note modules and package JSON file is coming as expected in here.

96
00:07:23,460 --> 00:07:29,280
So basically we have updated successfully and see the difference on the management console.

97
00:07:29,310 --> 00:07:35,940
You can see the folder structure comes appropriately under the my function to I have no modules, indexes

98
00:07:35,940 --> 00:07:43,650
and package JSON files and in the package JSON file you can see the x ray SDK dependency in our application.

99
00:07:43,890 --> 00:07:49,680
And the last step, if you come back to our command window in the last step is invoke updated lambda

100
00:07:49,680 --> 00:07:52,470
function code with the click commands.

101
00:07:52,500 --> 00:07:59,130
In order to do that, we have also JSON file in the event JSON file, we have number one and number

102
00:07:59,130 --> 00:08:01,380
two and we are following the same steps.

103
00:08:01,380 --> 00:08:07,740
If you scroll down, you can see in here we are going to invoke my function to with this event JSON

104
00:08:07,740 --> 00:08:13,560
object and if you paste command in your command window, hit the enter.

105
00:08:14,570 --> 00:08:16,780
You can see the this quote is 200.

106
00:08:16,790 --> 00:08:23,750
If you go to the response JSON file, you can see that the successful body response comes properly in

107
00:08:23,750 --> 00:08:24,830
our application.

108
00:08:25,140 --> 00:08:25,550
Okay.

109
00:08:25,550 --> 00:08:30,320
This was multiply our function and we have multiply with the number one and number two and calculate

110
00:08:30,320 --> 00:08:31,190
total number.

111
00:08:31,430 --> 00:08:39,850
As you can see that we have updated our lambda function with additional dependencies using a double

112
00:08:40,130 --> 00:08:41,240
click commands.
