1
00:00:00,360 --> 00:00:04,860
In this video, we are going to create a rest API for our hands on lab.

2
00:00:04,920 --> 00:00:08,550
We'll create microservices with Rest API and lambda function.

3
00:00:08,850 --> 00:00:16,260
So as you can see the image, we are going to create a rest API and we are exposing these these methods.

4
00:00:16,500 --> 00:00:23,070
S&amp;P method get product, get product, buy ID, post product, delete product by ID.

5
00:00:23,100 --> 00:00:30,060
So we will create these resource and method types into the rest API using the measurement console.

6
00:00:30,060 --> 00:00:31,650
So let's get started.

7
00:00:32,160 --> 00:00:34,800
Please open the A measurement console.

8
00:00:34,890 --> 00:00:37,680
In the last few years we have created product API.

9
00:00:37,830 --> 00:00:40,800
I would like to delete this one and create from the secret.

10
00:00:40,830 --> 00:00:46,440
Let's delete this product API and now we are going to create a rest API.

11
00:00:46,440 --> 00:00:54,420
So rest API provides provides and rest http and print for our lambda functions API gateway ROS to request

12
00:00:54,420 --> 00:00:57,900
to our lambda function and then returns the function response to the client.

13
00:00:58,140 --> 00:01:05,130
So in order to create this API, we should go to API Gateway and connect the rest API with button.

14
00:01:05,280 --> 00:01:09,810
So this will be redirecting to us, creating any rest API.

15
00:01:09,810 --> 00:01:17,400
So basically select the protocol as a rest and create an API and give the API name as a product.

16
00:01:17,400 --> 00:01:23,250
This API and end point type should be the regional and click the create button.

17
00:01:24,940 --> 00:01:30,670
So now we can design our HTTP methods according to our architecture.

18
00:01:30,700 --> 00:01:35,800
As you remember that our architecture in here, we will create these HTTP methods and resources.

19
00:01:35,860 --> 00:01:41,900
As you can see, that product should be the resource and the methods should be the get post and delete.

20
00:01:41,920 --> 00:01:47,050
So let's apply these into a major console for the rest API.

21
00:01:47,170 --> 00:01:49,950
We should start with the resource types.

22
00:01:49,960 --> 00:01:57,700
So if you click the actions and create resources, I'm going to create a resource which name is product?

23
00:01:57,820 --> 00:02:04,270
So we don't set any proxy for the product resources and we will create resources.

24
00:02:05,190 --> 00:02:09,040
So now under the product we can apply the HTTP methods.

25
00:02:09,060 --> 00:02:11,700
So I would like to start with the create method.

26
00:02:11,700 --> 00:02:14,850
So select these actions in the dropdown.

27
00:02:14,850 --> 00:02:19,590
This time we will create method, but make sure that you have selected these product resources.

28
00:02:19,710 --> 00:02:21,570
Actions create method.

29
00:02:21,570 --> 00:02:24,600
So I'm going to create get method.

30
00:02:24,810 --> 00:02:29,040
You can click this button and we have created the get method.

31
00:02:29,040 --> 00:02:32,430
So now integration type should be the lambda function.

32
00:02:32,430 --> 00:02:35,970
So we have set the integration type as a lambda function.

33
00:02:35,970 --> 00:02:41,130
But there's another complication which is the use lambda proxy integration.

34
00:02:41,130 --> 00:02:48,510
We should also check this box because this is basically redirect the request to the lambda function

35
00:02:48,510 --> 00:02:52,320
with request it is available in the event JSON file.

36
00:02:52,320 --> 00:02:54,990
So that's why I would like to check this box.

37
00:02:54,990 --> 00:02:57,870
And also we should provide the lambda function.

38
00:02:57,870 --> 00:03:02,070
If you write the product, it is com product page function.

39
00:03:02,070 --> 00:03:09,420
So now we are ready to set integration or http get method to do lambda function, click the say button,

40
00:03:09,420 --> 00:03:11,490
make sure that you have checked this box.

41
00:03:11,490 --> 00:03:18,360
Also because we write our code into lambda function according to this invocation, click the save button

42
00:03:18,360 --> 00:03:24,840
and it is said that you are about to give API Gateway permission to invoke your lambda function.

43
00:03:24,840 --> 00:03:31,230
So basically when we are clicked, okay, this will be required permissions to the lambda function.

44
00:03:31,230 --> 00:03:33,690
Lambda function has resource based policies.

45
00:03:33,720 --> 00:03:39,450
This will be automatically create a resource based policy to invoke lambda function from the list API

46
00:03:39,450 --> 00:03:46,680
gateway, click the okay button and this will be prepared or http get method for the product resources.

47
00:03:46,680 --> 00:03:48,720
We can see the get product request.

48
00:03:48,720 --> 00:03:55,110
So we finish the first part and you can see the Lambda Proxy and invoke the lambda function, which

49
00:03:55,110 --> 00:03:56,370
is the product function.

50
00:03:56,370 --> 00:04:03,390
So I will also follow the same steps for the post because we have get product and the post product.

51
00:04:03,390 --> 00:04:07,560
So that's why select the product resource actions create method.

52
00:04:07,560 --> 00:04:14,130
And this time I'm going to select the post and click this check icon and select integration type lambda

53
00:04:14,130 --> 00:04:16,860
function use lambda proxy integration.

54
00:04:17,100 --> 00:04:24,150
Choose the lambda function as a product function and click the say button and give the permission with

55
00:04:24,150 --> 00:04:24,570
clicking.

56
00:04:24,570 --> 00:04:25,110
Okay.

57
00:04:27,310 --> 00:04:34,690
As you can see that we have created get and post method for the products and it is adding the required

58
00:04:34,690 --> 00:04:40,760
permissions to lambda invocations and we are ready for the get and post operations.

59
00:04:40,780 --> 00:04:45,490
Now we have also two more API methods.

60
00:04:45,490 --> 00:04:47,590
You can see that we finished get and post.

61
00:04:47,620 --> 00:04:48,550
Now we should.

62
00:04:49,210 --> 00:04:52,930
They will hope to get product by ID and delete product by ID.

63
00:04:52,960 --> 00:05:00,310
For that reason we should come back to product section and after that we should create any resource

64
00:05:00,310 --> 00:05:07,180
pet with the ID information, let me click the product resource actions create resources.

65
00:05:07,180 --> 00:05:11,140
This time I'm going to add a resource with the ID information.

66
00:05:11,140 --> 00:05:19,720
So because we will get the ID, I can say the source name is a ID or get by ID product by ID you can

67
00:05:19,720 --> 00:05:21,340
give what you name it.

68
00:05:21,340 --> 00:05:27,250
So now we can click the create resource to complete this operation.

69
00:05:28,500 --> 00:05:35,580
So now it is ready for the product by ID, but we should also add the required method under the product

70
00:05:35,580 --> 00:05:37,170
ID for that purpose.

71
00:05:37,170 --> 00:05:45,990
Come to actions and create method and I'm going to create a get product by ID for that purpose at the

72
00:05:45,990 --> 00:05:50,430
get method and click this icon and select the lambda function.

73
00:05:50,850 --> 00:05:55,560
Use Lambda Proxy Integration CheckBox and right on the product function.

74
00:05:55,950 --> 00:05:59,220
Just click the save button, give required permission.

75
00:05:59,220 --> 00:06:07,320
So this is the get product by ID HTTP method and is the same way I'm going to add another method which

76
00:06:07,320 --> 00:06:14,160
is the delete is remember that we will lead by ID also I will follow the same configurations.

77
00:06:14,160 --> 00:06:19,050
Please make sure that you have also checked this box and set the integration type lambda.

78
00:06:19,080 --> 00:06:21,510
Give the function name and click button.

79
00:06:22,580 --> 00:06:23,210
Okay.

80
00:06:23,420 --> 00:06:32,300
So as you can see that now we have complete our methods, get and post product, get and delete buy

81
00:06:32,300 --> 00:06:34,370
ID product by ID operations.

82
00:06:34,370 --> 00:06:39,200
So now every method integrate with the same lambda function.

83
00:06:39,200 --> 00:06:42,980
So now we can deploy our API in the last step.

84
00:06:42,980 --> 00:06:49,190
We need to deploy our API so that we can access through the public for that purpose, come to product

85
00:06:49,190 --> 00:06:53,660
resources, go to the actions and click to deploy API.

86
00:06:53,660 --> 00:06:59,150
So in the deployment stage it is required a stage, so we should create a new stage.

87
00:06:59,150 --> 00:07:03,740
So I'm going to create a production stage and click the deploy button.

88
00:07:05,950 --> 00:07:13,870
So you can see the an invocation URL generated from the API gateway and we will try to accessing the

89
00:07:13,870 --> 00:07:16,210
URL from the web browser or the postman.

90
00:07:16,300 --> 00:07:22,630
So in order to test our API, we will test our API to make sure that it is working or not.

91
00:07:23,020 --> 00:07:25,870
We will use a web browser to invoke our API.

92
00:07:25,900 --> 00:07:32,590
If you right click open the top and you can see the missing authentication token because our raw definition

93
00:07:32,590 --> 00:07:33,400
is different.

94
00:07:33,430 --> 00:07:40,420
We can come here under the stage, open the production, and click the get button and see the correct

95
00:07:40,450 --> 00:07:42,340
URL that we can invoke.

96
00:07:42,370 --> 00:07:46,090
Adding the appending slash product right click opening top.

97
00:07:46,120 --> 00:07:49,860
You can see that this is invoke to a lambda function.

98
00:07:49,870 --> 00:07:52,690
See that response come from the lambda function.

99
00:07:52,690 --> 00:07:55,690
So that means we have created successfully.

100
00:07:55,810 --> 00:08:00,960
As you can see that we have developed Lambda Synchronous Microservices with API Gateway in the rest

101
00:08:00,970 --> 00:08:02,560
API and HTTP methods.
