Since we use the serverless function, also known as FaaS-Function as a Service- this is a Python code for the Lambda serverless function that updates a counter when the page is viewd and stores it in a DynamoDB table like this:
The JavaScript invokes the lambda funtion directly and shows the updated view count on the page.
Also the code for Lambda function is Dockerized and integrated via Jenkins, can be deployed to ECR for scalability.
An application loadbalancer (AWS-ALB) can also be added and further secured using a web application firewall (WAF).
The serverless application modeling (SAM) is used here. Other resources can be defined as Terraform code and deployed automatically.