Skip to content

dstanecki/website-visitor-count

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

👥 Website Visitor Count (Serverless + Terraform)

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.

🔧 How It Works

  1. A user visits your website.
  2. A JavaScript script calls your deployed API Gateway endpoint.
  3. The Lambda function:
    • Retrieves the current visitor count from DynamoDB.
    • Increments the count.
    • Returns the updated count as JSON.
  4. The website displays the count dynamically.

🚀 Getting Started

✅ Prerequisites

  • Terraform
  • AWS CLI with credentials configured (aws configure)
  • IAM permissions to create Lambda, API Gateway, and DynamoDB resources

1. Deploy with Terraform

terraform init
terraform apply

2. ⚙️ Add DynamoDB item manually

Inside provisioned VisitorCount table, add an item manually:

{
  "id": "count",
  "visitor_count": 0
}

3. Insert the JavaScript into your website

Use at example.html for reference.

About

Serverless website visitor count in Terraform using AWS Lambda, API Gateway, and DynamoDB

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors