1
00:00:00,150 --> 00:00:06,030
In this video, we are going to continue the development of Basket Lambda Microservices as a reminder

2
00:00:06,030 --> 00:00:11,730
that we have only one item left, which is the published message to Amazon event Bridge, which is the

3
00:00:11,730 --> 00:00:15,450
custom event plus with using the event bridge SDK libraries.

4
00:00:15,810 --> 00:00:21,260
For that purpose, please go to documentation first and understand which events we are going to use.

5
00:00:21,270 --> 00:00:26,550
Basically, we will use client event, bridge package, and this time we will use put event command

6
00:00:26,550 --> 00:00:29,310
in order to publish event to the Amazon event bridge.

7
00:00:29,340 --> 00:00:32,490
If you go to put event command, you can see the details in here.

8
00:00:32,520 --> 00:00:38,310
And also we can check the input and output parameters from the objects of the put events command input.

9
00:00:38,340 --> 00:00:42,510
You can see that it is expecting entities array and return back to us.

10
00:00:42,510 --> 00:00:44,120
Entities array and enter.

11
00:00:44,880 --> 00:00:46,950
Okay, let's get start implementation.

12
00:00:46,950 --> 00:00:51,720
So for that purpose, the first thing first we should create event bridge client JavaScript.

13
00:00:51,720 --> 00:00:55,620
So if you open the our project, you can come here and go to command text.

14
00:00:55,620 --> 00:01:00,510
We can see that I have create event bridge client JS And this is very similar what we have done in the

15
00:01:00,510 --> 00:01:01,560
previous sections.

16
00:01:01,560 --> 00:01:07,470
So basically this is the client object that exposed EB client to perform event bridge operations and

17
00:01:07,470 --> 00:01:10,380
after that we can apply and implement our logic.

18
00:01:10,380 --> 00:01:15,150
But before implementing this logic, in the index case, you can see here and come to third point,

19
00:01:15,150 --> 00:01:17,250
we are going to implement these publish message.

20
00:01:17,250 --> 00:01:23,850
We should understand the incoming payload to this lambda function and how we can interact with the Amazon

21
00:01:23,850 --> 00:01:24,510
event page.

22
00:01:24,510 --> 00:01:31,140
For that purpose, go to command text and see the expected payload that from Amazon API Gateway.

23
00:01:31,170 --> 00:01:37,080
This will be the HTTP post operation and it will include item price and detail type and source.

24
00:01:37,080 --> 00:01:43,500
Why we are requesting detail and detail type and the source attribute because when we define our event

25
00:01:43,500 --> 00:01:48,960
bridge, you can remember that our pattern is there is a two rules in the Amazon event bridge on our

26
00:01:48,960 --> 00:01:50,130
custom event plus.

27
00:01:50,130 --> 00:01:55,110
And the first one is the detail type, which is the checkout basket and the second one is the source.

28
00:01:55,110 --> 00:02:01,590
So we are using these event pattern rules in order to redirect and to target systems, which is the

29
00:02:01,590 --> 00:02:04,260
notification and the Amazon SKU.

30
00:02:04,290 --> 00:02:10,080
You can remember that we have to target Amazon SKU, SKU and notification microservices when we send

31
00:02:10,080 --> 00:02:10,920
the checkout event.

32
00:02:10,920 --> 00:02:14,250
These will be target to these two services.

33
00:02:14,340 --> 00:02:15,960
Okay, let's implement now.

34
00:02:15,960 --> 00:02:20,610
So if you go back to index case, I'm going to write codes under the third step.

35
00:02:20,610 --> 00:02:25,880
So first of all, I would like to start with the import statement because we have created the event

36
00:02:25,890 --> 00:02:32,250
bridge client JS and also we will use event libraries for that purpose to go on top of these indexes

37
00:02:32,250 --> 00:02:35,340
and come here and add the required import statements.

38
00:02:35,340 --> 00:02:41,850
These are the event commands from the client event bridge and also EB client from the event client tags.

39
00:02:41,880 --> 00:02:46,200
Please don't forget to write non JS after importing these statements.

40
00:02:46,200 --> 00:02:50,790
We can use these statements in the third step when we are publishing the message.

41
00:02:50,790 --> 00:02:54,120
So it is very basic steps that we have done so far.

42
00:02:54,150 --> 00:02:59,490
Basically, we will prepare our parameters and after that paste these parameters into put event command,

43
00:02:59,490 --> 00:03:05,700
be using the EB client in order to send event bridge and after that log the incoming data message from

44
00:03:05,700 --> 00:03:06,780
the send operation.

45
00:03:06,800 --> 00:03:12,270
This available operation that we are going to use if we check the parameters, parameters are include

46
00:03:12,270 --> 00:03:18,480
entities array as you remember that and we have only send one entity which is the one event publishing

47
00:03:18,480 --> 00:03:25,110
that the source is basket request source, the expected source as a combat and so on.

48
00:03:25,110 --> 00:03:27,780
And the detail is actual JSON object.

49
00:03:27,780 --> 00:03:32,280
That's why we are passing the basket request and JSON trying to hold object.

50
00:03:32,310 --> 00:03:33,660
The third one is detail type.

51
00:03:33,660 --> 00:03:38,880
It is also important because we have a filter on the event pattern, so we are placing basket request

52
00:03:39,180 --> 00:03:39,870
detail type.

53
00:03:39,870 --> 00:03:45,000
This will be the checkout basket and we don't have any resource name, event bus name, which is our

54
00:03:45,000 --> 00:03:46,200
custom event bus name.

55
00:03:46,200 --> 00:03:48,450
Which name is checkout basket event pass?

56
00:03:48,450 --> 00:03:54,480
You can put these value as an environment variable of lambda function, but for now I am setting card

57
00:03:54,480 --> 00:03:55,560
called value in here.

58
00:03:55,560 --> 00:04:01,230
So as you can see that we have also implement the third step which including the import statement and

59
00:04:01,230 --> 00:04:07,800
these are the parameters that we are interacting with event client as you can see that we basically

60
00:04:07,800 --> 00:04:15,120
develop basket microservices, which publishing message to custom event pass using database SDK libraries

61
00:04:15,120 --> 00:04:17,850
and finish the development of basket microservices.
