1
00:00:00,240 --> 00:00:08,250
In this video we are going to see using Node.js s modules and top level weight statements in a lambda

2
00:00:08,250 --> 00:00:11,310
and how it could be benefit in your application.

3
00:00:11,490 --> 00:00:17,850
So actually there is an article written by Dan Fox, Principal Spatial Solutions Architect in the service

4
00:00:17,850 --> 00:00:18,520
part of the ADA.

5
00:00:18,710 --> 00:00:19,170
Yes.

6
00:00:19,170 --> 00:00:26,100
So in this article, Dan Fox is developing an example project and compares to Node.js is modules with

7
00:00:26,100 --> 00:00:29,610
the common JS modules with using top level statements.

8
00:00:29,940 --> 00:00:37,110
If you open this article, he basically explains how Node.js is modules can help performance of lambda

9
00:00:37,110 --> 00:00:37,830
functions.

10
00:00:37,830 --> 00:00:43,710
This is especially useful when used with the provision concurrency and reduce cold start times.

11
00:00:43,950 --> 00:00:49,860
You can see that it is starting designating a function as a model for that purpose.

12
00:00:49,860 --> 00:00:55,560
It is adding the type module statement into package JSON and in the index case it is using the import

13
00:00:55,560 --> 00:01:01,770
keyword and using the export codes in order to expose this 100 method.

14
00:01:01,800 --> 00:01:08,250
This is the lambda function and we will use this format as we checked our case management console.

15
00:01:08,280 --> 00:01:14,280
These are the using exports handler, but from now on we will use a script six.

16
00:01:14,280 --> 00:01:21,090
So that's why we will design our lambda functions, be using the latest version of the script.

17
00:01:21,090 --> 00:01:24,870
So that's why we will export the 100 method in our lambda function.

18
00:01:24,870 --> 00:01:27,210
We're using the export console handler.

19
00:01:27,360 --> 00:01:34,770
So if you scroll down, he's explaining very good topics, for example, explaining the provision concurrency

20
00:01:34,770 --> 00:01:42,150
in lambda function and how Node.js will perform for these concurrent concurrency on lambda function.

21
00:01:42,150 --> 00:01:46,200
And the code start to improving the code start benefits.

22
00:01:46,200 --> 00:01:53,640
We should use the top level sync eight function because this allows the developers to use async pivot,

23
00:01:53,640 --> 00:02:00,510
which is basically perform the asynchronous initialization called before the 100 invocation.

24
00:02:00,510 --> 00:02:02,040
This is very important.

25
00:02:02,040 --> 00:02:09,840
So that means we can use Node.js functions with async, await keywords in the script six and modularized

26
00:02:09,840 --> 00:02:11,760
version three of the SDK.

27
00:02:11,790 --> 00:02:18,570
It is performing the asynchronous initialization and before 100 invocation the code already initialize

28
00:02:18,570 --> 00:02:19,230
for us.

29
00:02:19,230 --> 00:02:26,550
So the topic is very important in this article because he is testing with two methods.

30
00:02:26,550 --> 00:02:28,140
The first method is common.

31
00:02:28,140 --> 00:02:29,790
JS As you can see in here, common.

32
00:02:29,790 --> 00:02:37,920
JS It is using the keywords and using the exports handler to perform this operation in the lambda function

33
00:02:37,920 --> 00:02:47,100
and as the same method is written with the execute modules and using the Dynamo DB Node.js JavaScript

34
00:02:47,100 --> 00:02:55,920
SDK Version three package using the only client and command object and perform the same thing in the

35
00:02:55,920 --> 00:02:57,000
lambda function.

36
00:02:57,000 --> 00:03:05,190
And after that he is created this project that contains two lambda functions you can see in this image

37
00:03:05,280 --> 00:03:12,690
and one that consisting the yes modules and another that is the common JS modules both function are

38
00:03:12,690 --> 00:03:20,070
configured to respond a single API gateway endpoints and the important topic is the results.

39
00:03:20,070 --> 00:03:26,430
So if you see the results here, you can find the side by side comparison of the results of two load

40
00:03:26,430 --> 00:03:33,240
tests of 600 requests each and the left show of the result for the common JS module and the right shows

41
00:03:33,240 --> 00:03:35,130
the result of the circuit module.

42
00:03:35,220 --> 00:03:44,760
You can see for the common JS module takes 600 milliseconds while the modules takes 300 milliseconds.

43
00:03:44,790 --> 00:03:50,310
A performance improvement about 50% this competition load tests.

44
00:03:50,310 --> 00:03:57,090
So in order to summarize with using the secret modules and top level evade statements, we can gain

45
00:03:57,090 --> 00:04:00,480
almost 50% performance advantage.

46
00:04:00,480 --> 00:04:06,690
And it is very crucial when it comes to manage lambda provision concurrency and manage code start.

47
00:04:06,870 --> 00:04:12,510
So as you can see that this is the best practice to use Node.js runtime in Lambda functions and using

48
00:04:12,790 --> 00:04:19,800
script six modules provide serious performance benefits and we will use a async JavaScript version three

49
00:04:19,800 --> 00:04:26,310
V to execute six standards when interacting with native resources into Node.js Lambda functions.

50
00:04:26,310 --> 00:04:33,300
Now we have node up to use this combination into a server services and we will follow these best practices

51
00:04:33,300 --> 00:04:34,170
during the course.

52
00:04:34,200 --> 00:04:35,700
Now let's get started.
