This repository contains a serverless solution to count website visits using AWS Lambda, API Gateway, and DynamoDB. It includes:
- A Python Lambda function that increments a visitor counter stored in DynamoDB.
- A JavaScript snippet to call the API and display the current count on a web page.
- Terraform files to deploy the entire infrastructure automatically.
- A user visits your website.
- A JavaScript script calls your deployed API Gateway endpoint.
- The Lambda function:
- Retrieves the current visitor count from DynamoDB.
- Increments the count.
- Returns the updated count as JSON.
- The website displays the count dynamically.
- Terraform
- AWS CLI with credentials configured (
aws configure) - IAM permissions to create Lambda, API Gateway, and DynamoDB resources
terraform init
terraform applyInside provisioned VisitorCount table, add an item manually:
{
"id": "count",
"visitor_count": 0
}Use at example.html for reference.