A serverless API to count user visits using AWS Lambda and DynamoDB — supports GET and POST methods.
In Lambda → Configuration → Permissions → click the role name -> Attach this policy
Attach this inline policy to the Lambda execution role to allow updating visit counts in DynamoDB.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Statement1",
"Effect": "Allow",
"Action": ["dynamodb:UpdateItem"],
"Resource": [
"arn:aws:dynamodb:<your-region>:<your-account-id>:table/VisitCounter"
]
}
]
}Example: arn:aws:dynamodb:ap-south-1:123456789012:table/VisitCounter
Get the current visit count for a user
# Replace <api-id> and <userName> accordingly
curl "https://<api-id>.execute-api.ap-south-1.amazonaws.com/?user=<userName>"Increment the visit count for a user
# Replace <api-id> and <userName> accordingly
curl -X POST "https://<api-id>.execute-api.ap-south-1.amazonaws.com/" \
-H "Content-Type: application/json" \
-d '{"user": "userName"}'MIT — feel free to use and modify.