After setting up the DynamoDB table, it was time to store the visitor count data of my website into that table. This is not done directly using Javascript code, instead the the website calls an API - Application Programming Interface created in AWS API Gateway
, interfaced with its respective lambda function to perform the task, every time it is loaded.
API Gateway
From the API Gateway console I selected create API.
And selected build
REST API.
Then I mentioned the name of my API and set endpoint preferrence as edge location optimised.
Once the api was created, I create an option
method with integration point as mock
.
And another POST
method, with integration point as Lambda function, mentioning the name of the Lambda function.
Then I had to enable CORS from the actions menu. Without CORS enabled, client will not be able fetch data from the function.
Once that was done, it was time to deploy the API.
I selected a new stage with name dev
and deployed the API.
After the deployment, I got the API invoke URL as below. This is the URL that fetched by my JavaScript functon callAPI
.(Read more)
The API calls to Lambda function have been tested in Postman.
as well as from the console (Read more - Step 6
).
AWS::Serverless::Api
However this was the manual method of creating an API from AWS console, the final version of the source code is using an API that is created using SAM template (Read more) with the API name as aws-sam-komlalebu
having a different invoke URL. This api calls the lambda function KomlalebuFunction
.
This website has a primary API to load count data to dynamoDB table with the help of a lambda function.
[API Gateway: aws-sam-komlalebu + Lambda: KomlalebuFunction]
as well as separate API's for retrieving likes/dislikes counts back from the table (which we will see later)**.
And the API was setup.
Top comments (0)