Skip to content

A serverless API to count and store user visits using AWS Lambda and DynamoDB — fully modular and easy to deploy.

License

Shriansh2002/lambda-with-dynamo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Visit Counter (AWS Lambda + DynamoDB)

A serverless API to count user visits using AWS Lambda and DynamoDB — supports GET and POST methods.

JavaScript AWS Lambda DynamoDB

🔐 IAM Configuration

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

🧪 Testing

GET

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>"

POST

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"}'

📜 License

MIT — feel free to use and modify.

About

A serverless API to count and store user visits using AWS Lambda and DynamoDB — fully modular and easy to deploy.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published