1
00:00:00,270 --> 00:00:03,480
In this video, we are going to developing our lambda function.

2
00:00:03,480 --> 00:00:07,680
So the first step is we are listing objects into the bucket.

3
00:00:07,680 --> 00:00:13,260
So that means think about that with the incoming event JSON object, we can get the bucket name and

4
00:00:13,260 --> 00:00:19,800
after that in the lambda function, we will interact with the Amazon S3 passing the bucket name and

5
00:00:19,800 --> 00:00:21,630
get the object from the bucket.

6
00:00:21,630 --> 00:00:25,680
We're using a WS SDK package, so let's get started.

7
00:00:25,800 --> 00:00:28,170
Please open the index JS file.

8
00:00:28,170 --> 00:00:30,810
So I'm going to listing objects in the bucket name.

9
00:00:30,810 --> 00:00:35,190
So that means I have the interaction with the S3 client object.

10
00:00:35,190 --> 00:00:40,400
And for that purpose we are going to use these list object version two command.

11
00:00:40,400 --> 00:00:42,510
So you can see the example in here.

12
00:00:42,510 --> 00:00:47,700
We can come here and see the list object version two command and this is the example we will implement

13
00:00:47,700 --> 00:00:48,630
this example.

14
00:00:48,630 --> 00:00:51,360
So let me start to developing first.

15
00:00:51,360 --> 00:00:54,910
First of all, I'm going to develop try case block.

16
00:00:54,960 --> 00:00:58,860
We can come here and from the cache block.

17
00:01:00,790 --> 00:01:01,630
Now in the tribe.

18
00:01:01,630 --> 00:01:07,420
Look, we basically use a steady client and center list object version to command.

19
00:01:07,510 --> 00:01:10,060
Let me develop these codes.

20
00:01:10,060 --> 00:01:15,810
So as you remember that these are the almost the same steps when we have interaction with the client.

21
00:01:15,820 --> 00:01:20,710
The only difference is we are developing the handle method, which is the lambda function code.

22
00:01:20,710 --> 00:01:22,660
But the idea is the same.

23
00:01:22,660 --> 00:01:27,490
We are using the client and sent to this object version to command with the parameters.

24
00:01:27,520 --> 00:01:34,120
Also, I'm going to create the parameters and after that we are logging the incoming data from the H3.

25
00:01:34,300 --> 00:01:38,380
Okay, now let me continue with developing the parameters.

26
00:01:38,380 --> 00:01:41,290
So we should define the parameters in here.

27
00:01:41,440 --> 00:01:44,590
Basically, in the parameters we should provide the bucket name.

28
00:01:44,590 --> 00:01:48,790
We can check the list object version to command request.

29
00:01:48,790 --> 00:01:51,310
The only important object is the bucket.

30
00:01:51,310 --> 00:01:54,190
I'm placing the bucket name in here in the previous.

31
00:01:54,190 --> 00:01:58,360
In the next videos we will get this bucket name from the incoming event JSON.

32
00:01:58,360 --> 00:02:04,120
But this time I would like to show with the hardcoded and give the bucket name and paste the parameters

33
00:02:04,120 --> 00:02:08,380
in here in the list object command and send the data with S3 client.

34
00:02:08,380 --> 00:02:14,660
So that means we have performed the first step listing object in the bucket, but please don't forget

35
00:02:14,660 --> 00:02:15,670
that required package.

36
00:02:15,670 --> 00:02:20,920
Please come here and import required packets for that purpose I'm going to import one by one.

37
00:02:21,370 --> 00:02:25,330
Let me go on top of these indexes and import this statement.

38
00:02:25,330 --> 00:02:32,190
So we will import list, object command and also import client separate Node.js module and don't forget

39
00:02:32,190 --> 00:02:35,560
to add the JS extension, otherwise it won't be work.

40
00:02:35,800 --> 00:02:36,370
Okay.

41
00:02:36,370 --> 00:02:41,140
So now I would like to test this code in my local computer.

42
00:02:41,170 --> 00:02:48,400
Even we develop the Lambda 100 code before we deploy these methods and these codes into lambda function.

43
00:02:48,400 --> 00:02:53,800
We can test and verify the codes and into our local computer.

44
00:02:53,830 --> 00:02:58,360
In order to do that, I'm going to copy this hundred method and.

45
00:02:59,150 --> 00:03:05,240
At the end of these indexes, I am going to invoke and call these one methods.

46
00:03:05,270 --> 00:03:12,920
So first of all, I'm calling this handle method and after that I will use note command as we did before.

47
00:03:12,950 --> 00:03:16,800
So this is the good practice with using the note command.

48
00:03:16,820 --> 00:03:22,080
With the note command, we can verify that this function is working fine or not.

49
00:03:22,100 --> 00:03:29,030
And after that, we should command this 100 method and zip this file and deploy the lambda function.

50
00:03:29,030 --> 00:03:34,730
But since that time we can perform our local test to running the note commands.

51
00:03:34,730 --> 00:03:36,530
If you open the our.

52
00:03:37,430 --> 00:03:38,390
Command window.

53
00:03:38,420 --> 00:03:42,700
You can run the mode, command and paste the indexes.

54
00:03:42,710 --> 00:03:47,060
So this will be run these indexes and go to 100 method.

55
00:03:47,060 --> 00:03:53,480
In the handle method, we basically perform that communicating with S3 listing to objects into the bucket,

56
00:03:53,480 --> 00:03:55,550
which the given name of this one.

57
00:03:55,550 --> 00:04:00,120
So let's hit enter and try to test these code.

58
00:04:00,140 --> 00:04:00,470
Yes.

59
00:04:00,470 --> 00:04:02,630
As you can see that we have successful test.

60
00:04:02,630 --> 00:04:09,890
Basically request seems either undefined because we don't passing any event JSON, but we can also paste

61
00:04:09,890 --> 00:04:12,710
this event JSON into our application.

62
00:04:12,800 --> 00:04:18,920
But after that, we basically get the success response from the S3 client object.

63
00:04:18,920 --> 00:04:23,120
You can come here and see the service code and see the content in here.

64
00:04:23,120 --> 00:04:29,990
So in the S3 bucket of this name of the bucket, there is a key index, HTML file and you can see the

65
00:04:29,990 --> 00:04:35,090
other attributes and there is only one column, one object into this bucket.

66
00:04:35,090 --> 00:04:41,690
So as you can see that we have successfully performed our local test before deploying this application.

67
00:04:41,690 --> 00:04:47,120
So this is the our way of working and development of the Lambda development approach.

68
00:04:47,120 --> 00:04:53,420
First we verify it is working our local computer with the node command and after that we will compress

69
00:04:53,420 --> 00:04:57,770
and deploy our code to the lambda function and test with the real locations.

70
00:04:58,070 --> 00:05:02,750
After verify our function code, let's review our function code.

71
00:05:02,780 --> 00:05:10,070
If you scroll down and see that basically it is returning a response as a subsequent 200.

72
00:05:10,070 --> 00:05:15,880
So if you look at our one method, you can see that we are returning helo response, which is status

73
00:05:15,920 --> 00:05:22,460
code of 200, but we don't need to return any code from our function because we are asynchronous function

74
00:05:22,460 --> 00:05:27,590
that triggers from the Amazon S3 so we don't need to return value for that purpose.

75
00:05:27,590 --> 00:05:31,910
I'm going to remove these all return statement and come here.

76
00:05:31,910 --> 00:05:39,920
And we basically covered the cache block and in the case block we can log the error if there is an error,

77
00:05:39,920 --> 00:05:41,030
and that's all.

78
00:05:41,030 --> 00:05:48,380
So for our 100 method, we don't need to return any synchronous response because we are triggering from

79
00:05:48,380 --> 00:05:50,090
S3 asynchronously.

80
00:05:50,360 --> 00:05:57,110
As you can see that we have only try catch block and log the asynchronous operation that we can understand

81
00:05:57,110 --> 00:05:59,710
what's happening in this function code.

82
00:05:59,720 --> 00:06:09,230
So we have already test this code with the node command you can run again and test your index JS and

83
00:06:09,230 --> 00:06:16,580
see that our objects listed from the bucket name and we are ready for to continue the second operation.

84
00:06:16,580 --> 00:06:24,830
So in the next video we are going to iterate these bucket objects and write these bucket objects on

85
00:06:24,830 --> 00:06:26,060
the Dynamo DB table.
