In this video, we are going to create a rest API for our hands on lab.
We'll create microservices with Rest API and lambda function.
So as you can see the image, we are going to create a rest API and we are exposing these these methods.
S&P method get product, get product, buy ID, post product, delete product by ID.
So we will create these resource and method types into the rest API using the measurement console.
So let's get started.
Please open the A measurement console.
In the last few years we have created product API.
I would like to delete this one and create from the secret.
Let's delete this product API and now we are going to create a rest API.
So rest API provides provides and rest http and print for our lambda functions API gateway ROS to request
to our lambda function and then returns the function response to the client.
So in order to create this API, we should go to API Gateway and connect the rest API with button.
So this will be redirecting to us, creating any rest API.
So basically select the protocol as a rest and create an API and give the API name as a product.
This API and end point type should be the regional and click the create button.
So now we can design our HTTP methods according to our architecture.
As you remember that our architecture in here, we will create these HTTP methods and resources.
As you can see, that product should be the resource and the methods should be the get post and delete.
So let's apply these into a major console for the rest API.
We should start with the resource types.
So if you click the actions and create resources, I'm going to create a resource which name is product?
So we don't set any proxy for the product resources and we will create resources.
So now under the product we can apply the HTTP methods.
So I would like to start with the create method.
So select these actions in the dropdown.
This time we will create method, but make sure that you have selected these product resources.
Actions create method.
So I'm going to create get method.
You can click this button and we have created the get method.
So now integration type should be the lambda function.
So we have set the integration type as a lambda function.
But there's another complication which is the use lambda proxy integration.
We should also check this box because this is basically redirect the request to the lambda function
with request it is available in the event JSON file.
So that's why I would like to check this box.
And also we should provide the lambda function.
If you write the product, it is com product page function.
So now we are ready to set integration or http get method to do lambda function, click the say button,
make sure that you have checked this box.
Also because we write our code into lambda function according to this invocation, click the save button
and it is said that you are about to give API Gateway permission to invoke your lambda function.
So basically when we are clicked, okay, this will be required permissions to the lambda function.
Lambda function has resource based policies.
This will be automatically create a resource based policy to invoke lambda function from the list API
gateway, click the okay button and this will be prepared or http get method for the product resources.
We can see the get product request.
So we finish the first part and you can see the Lambda Proxy and invoke the lambda function, which
is the product function.
So I will also follow the same steps for the post because we have get product and the post product.
So that's why select the product resource actions create method.
And this time I'm going to select the post and click this check icon and select integration type lambda
function use lambda proxy integration.
Choose the lambda function as a product function and click the say button and give the permission with
clicking.
Okay.
As you can see that we have created get and post method for the products and it is adding the required
permissions to lambda invocations and we are ready for the get and post operations.
Now we have also two more API methods.
You can see that we finished get and post.
Now we should.
They will hope to get product by ID and delete product by ID.
For that reason we should come back to product section and after that we should create any resource
pet with the ID information, let me click the product resource actions create resources.
This time I'm going to add a resource with the ID information.
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
give what you name it.
So now we can click the create resource to complete this operation.
So now it is ready for the product by ID, but we should also add the required method under the product
ID for that purpose.
Come to actions and create method and I'm going to create a get product by ID for that purpose at the
get method and click this icon and select the lambda function.
Use Lambda Proxy Integration CheckBox and right on the product function.
Just click the save button, give required permission.
So this is the get product by ID HTTP method and is the same way I'm going to add another method which
is the delete is remember that we will lead by ID also I will follow the same configurations.
Please make sure that you have also checked this box and set the integration type lambda.
Give the function name and click button.
Okay.
So as you can see that now we have complete our methods, get and post product, get and delete buy
ID product by ID operations.
So now every method integrate with the same lambda function.
So now we can deploy our API in the last step.
We need to deploy our API so that we can access through the public for that purpose, come to product
resources, go to the actions and click to deploy API.
So in the deployment stage it is required a stage, so we should create a new stage.
So I'm going to create a production stage and click the deploy button.
So you can see the an invocation URL generated from the API gateway and we will try to accessing the
URL from the web browser or the postman.
So in order to test our API, we will test our API to make sure that it is working or not.
We will use a web browser to invoke our API.
If you right click open the top and you can see the missing authentication token because our raw definition
is different.
We can come here under the stage, open the production, and click the get button and see the correct
URL that we can invoke.
Adding the appending slash product right click opening top.
You can see that this is invoke to a lambda function.
See that response come from the lambda function.
So that means we have created successfully.
As you can see that we have developed Lambda Synchronous Microservices with API Gateway in the rest
API and HTTP methods.