Loading…
Visitor Counter with AWS Lambda, API Gateway, and DynamoDB
Project Overview
This project implements a serverless visitor counter using AWS Lambda, API Gateway, and DynamoDB to store and retrieve visitor counts. The goal was to build a scalable and cost-effective solution to track and display real-time visitor counts on a static web page hosted on AWS S3.
Technologies Used
- AWS Lambda
- API Gateway
- DynamoDB
- S3 (Static Website Hosting)
- CloudFront (CDN)
- JavaScript for Frontend
Step-by-Step Development Process
- Frontend Setup: I created an HTML page hosted on an AWS S3 bucket. The page includes a JavaScript function that makes an API call to update and display the visitor counter.
- API Gateway Configuration: I set up an API Gateway to expose an endpoint that the frontend can use to interact with the Lambda function. This endpoint acts as the interface between the frontend and backend.
- AWS Lambda Function: The Lambda function handles requests from the API Gateway, either incrementing or retrieving the visitor count from DynamoDB. The function is written in Node.js.
- DynamoDB Setup: DynamoDB is used to store the visitor count. I created a table with a primary key to track the number of visitors by a unique ID.
- Connecting All Components: After deploying the Lambda function and configuring the API Gateway, I connected the frontend to make HTTP requests to the API. The JavaScript fetch function retrieves the current count and updates the UI.
- CloudFront and SSL: I used CloudFront to serve the static site with a custom domain (aterakrofi.com) and enabled SSL using AWS Certificate Manager to provide a secure connection.
Challenges Faced
- CORS Issues: Initially, I encountered CORS (Cross-Origin Resource Sharing) issues when making requests from the frontend to the API Gateway. I resolved this by properly configuring CORS in the API Gateway to allow requests from my domain.
- DynamoDB Permissions: Another challenge was ensuring that the Lambda function had the correct IAM role with permissions to access DynamoDB. I used AWS IAM to assign the necessary permissions.
Final Outcome
The visitor counter was successfully implemented, providing a scalable, serverless solution to track and display real-time visitor counts. The use of DynamoDB ensures that the system is highly available and cost-effective. CloudFront further optimized the loading speed of the static site across different regions.
Next Steps
Possible future enhancements include integrating a more detailed analytics dashboard to track visitor data and adding error handling mechanisms to account for potential failures in API calls.
← Back to Resume