Chunk 2: Crafting the Backend - Visitor Counter

Chunk 2: Crafting the Backend - Visitor Counter

"So this is the part of the challenge that separates the wannabes from the champions." - CRC

And it is true, speaking for Chunks 2 and 3. This part is the most challenging thus far. This is where the visitor counter is set up and later on in Chunk 3, displayed on the webpage. Simply, this requires a cloud-based API that communicates with the website.


Quick Note: This is only a part of my effort to finish the Cloud Resume Challenge. Here is the start of my blog. And here's the resume.


Individually, the components of this chunk are not very complex but putting them to work altogether is the steepest part of the learning curve. The components are:

  • DynamoDB table

  • Python code hosted in Lambda to record page views in DDB.

  • API Gateway which allows for Lambda function to be called from the website.

The first step is setting up the permissions of Lambda to have access and privileges to DDB. This is a good guide.

Next is creating the Lambda function choosing Python for runtime, and the previously created permissions. Then, before writing the code, its better to have the DDB table set up. Check out this AWS resource for setting up DDB tables.

Once the table is created, the Python code can now be written and this is a good quick guide for code to update values in atable. However, I would suggest checking out the Boto3 Documentation as well for straight from the source examples and adding try/except in the code to catch errors and this AWS resource is a good example for that. The function should be able to return the iterated value from the table after deploying and testing through the console.

After, the API Gateway could be set up specifying the integration with the Lambda function.

Following this window, a route should be configured to point to the function. Otherwise, the API will not be able to call the Lambda function. A trigger should then be added to the Lambda function specifying which API the trigger is expected from. Permissions will automatically be added in the Configuration section for Lambda to be triggered by the API.

When all set, Postman can be used to check if the API endpoint works! That's it for Chunk 2.

If the expected results are not showing, make sure that configurations are all set! I spent a lot of time figuring out how one service connects to another and which settings are needed. Along the way, I had to read about a lot of different terminologies to understand they whys of each! It's really part of the learning process.

Hope you reach out for any questions. I'd love to hear from you! All the best to you and cheers!