All Projects → sbstjn → Serverless Analytics

sbstjn / Serverless Analytics

Licence: mit
Track website visitors with Serverless Analytics using Kinesis, Lambda, and TypeScript.

Projects that are alternatives of or similar to Serverless Analytics

Aws Mobile React Sample
A React Starter App that displays how web developers can integrate their front end with AWS on the backend. The App interacts with AWS Cognito, API Gateway, Lambda and DynamoDB on the backend.
Stars: ✭ 650 (+196.8%)
Mutual labels:  aws, serverless, lambda, dynamodb
Aws Mobile React Native Starter
AWS Mobile React Native Starter App https://aws.amazon.com/mobile
Stars: ✭ 2,247 (+926.03%)
Mutual labels:  aws, serverless, lambda, dynamodb
Dazn Lambda Powertools
Powertools (logger, HTTP client, AWS clients, middlewares, patterns) for Lambda functions.
Stars: ✭ 501 (+128.77%)
Mutual labels:  aws, serverless, lambda, dynamodb
Komiser
☁️ Cloud Environment Inspector 👮🔒 💰
Stars: ✭ 2,684 (+1125.57%)
Mutual labels:  aws, serverless, lambda, dynamodb
Awesome Aws
A curated list of awesome Amazon Web Services (AWS) libraries, open source repos, guides, blogs, and other resources. Featuring the Fiery Meter of AWSome.
Stars: ✭ 9,895 (+4418.26%)
Mutual labels:  aws, serverless, lambda, dynamodb
Workshop Donkeytracker
Workshop to build a serverless tracking application for your mobile device with an AWS backend
Stars: ✭ 27 (-87.67%)
Mutual labels:  aws, serverless, lambda, dynamodb
Sqs Worker Serverless
Example for SQS Worker in AWS Lambda using Serverless
Stars: ✭ 164 (-25.11%)
Mutual labels:  aws, serverless, lambda, dynamodb
Realworld Dynamodb Lambda
λ serverless backend implementation for RealWorld using AWS DynamoDB + Lambda
Stars: ✭ 185 (-15.53%)
Mutual labels:  aws, serverless, lambda, dynamodb
Historical
A serverless, event-driven AWS configuration collection service with configuration versioning.
Stars: ✭ 85 (-61.19%)
Mutual labels:  aws, serverless, lambda, dynamodb
Lambda Refarch Webapp
The Web Application reference architecture is a general-purpose, event-driven, web application back-end that uses AWS Lambda, Amazon API Gateway for its business logic. It also uses Amazon DynamoDB as its database and Amazon Cognito for user management. All static content is hosted using AWS Amplify Console.
Stars: ✭ 1,208 (+451.6%)
Mutual labels:  aws, serverless, lambda, dynamodb
Iopipe Js Core
Observe and develop serverless apps with confidence on AWS Lambda with Tracing, Metrics, Profiling, Monitoring, and more.
Stars: ✭ 123 (-43.84%)
Mutual labels:  aws, serverless, lambda, analytics
Designing Cloud Native Microservices On Aws
Introduce a fluent way to design cloud native microservices via EventStorming workshop, this is a hands-on workshop. Contains such topics: DDD, Event storming, Specification by example. Including the AWS product : Serverless Lambda , DynamoDB, Fargate, CloudWatch.
Stars: ✭ 131 (-40.18%)
Mutual labels:  aws, serverless, lambda, dynamodb
Aws Auto Remediate
Open source application to instantly remediate common security issues through the use of AWS Config
Stars: ✭ 191 (-12.79%)
Mutual labels:  aws, serverless, lambda
Refunc
A lib make building AWS Lambda compatible layer easily
Stars: ✭ 144 (-34.25%)
Mutual labels:  aws, serverless, lambda
Jets
Ruby on Jets
Stars: ✭ 1,915 (+774.43%)
Mutual labels:  aws, serverless, lambda
Aws Serverless Cicd Workshop
Learn how to build a CI/CD pipeline for SAM-based applications
Stars: ✭ 158 (-27.85%)
Mutual labels:  aws, serverless, lambda
Serverless Sam
Serverless framework plugin to export AWS SAM templates for a service
Stars: ✭ 143 (-34.7%)
Mutual labels:  aws, serverless, lambda
Serverless Next.js
⚡ Deploy your Next.js apps on AWS Lambda@Edge via Serverless Components
Stars: ✭ 2,977 (+1259.36%)
Mutual labels:  aws, serverless, lambda
Aws Lambda Power Tuning
AWS Lambda Power Tuning is an open-source tool that can help you visualize and fine-tune the memory/power configuration of Lambda functions. It runs in your own AWS account - powered by AWS Step Functions - and it supports three optimization strategies: cost, speed, and balanced.
Stars: ✭ 3,040 (+1288.13%)
Mutual labels:  aws, serverless, lambda
Serverless Dynamodb Autoscaling
Serverless Plugin for Amazon DynamoDB Auto Scaling configuration.
Stars: ✭ 142 (-35.16%)
Mutual labels:  aws, serverless, dynamodb

Serverless Analytics ⚡️

MIT License Read Tutorial

Example project and proof of concept for a personal serverless Google Analytics clone to track website visitors. You can read more about Serverless Analytics with Amazon Kinesis and AWS Lambda on sbstjn.com

Components

After deploying the service you will have an HTTP endpoint using Amazon API Gateway that accepts requests and puts them into a Kinesis Stream. A Lambda function processes the stream and writes basic metrics about how many visitors you have per absolute URL to DynamoDB.

To access the tracked data, a basic dashboard with a JSON API is included as well. This should be a perfect starting point for you to create your own analytics service.

Tracking Service

  • Amazon Kinesis to stream visitor events
  • Amazon API Gateway for Kinesis HTTP proxy
  • Amazon DynamoDB for data storage
  • AWS Lambda to process visitor events

Dashboard

Example

The use of two API Gateways (data tracking and reading) is intended. You might have different settings for tracking and data access when you build something meaningful out of this example.

Configuration

All settings can be customized in the serverless.yml configuration file. You can easily change the DynamoDB Table, Kinesis Stream and API Gateway tracking resource name:

service: sls-analytics

custom:
  names:
    bucket: 
      website: ${self:service}-website-example
      dashboard: ${self:service}-website-dashboard
    resource: track
    dynamodb: ${self:service}-data
    kinesis: ${self:service}-stream

The S3 Bucket configuration is only needed for the included example website and dashboard. If you don't need the examples, have a look at the scripts/deploy.sh file and disable the deployment and remove the CloudFormation resources from the serverless.yml file.

Amazon requires unique names for S3 buckets and other resources. Please rename at least the service before you try to deploy the example!

Deployment

s3sync requires you to set AWS access keys as environmental variables.

  AWS_ACCESS_KEY=abc123
  AWS_SECRET_KEY=def456

Deploy script uses jq to read variables from generated output during deployment process. If you don't have jq installed, download it here.

Running yarn deploy will trigger a serverless deployment. After the output of your CloudFormation Stack is available, the included static websites will be generated (using the hostname from the stack output) and uploaded to the configured S3 buckets. As the last step, the deploy process will display the URLs of the example website and dashboard:

# Install dependencies
$ > yarn install
# Deploy 
$ > yarn deploy

[…]

Dashboard:  http://sls-analytics-dashboard.s3-website-us-east-1.amazonaws.com/
Website:    http://sls-analytics-website.s3-website-us-east-1.amazonaws.com/

The website includes a simple HTML file, some stylings, and a few JavaScript lines that send a request to the tracking API on every page load. Open the URL in a web browser, hit a few times the refresh button and take a look at the DynamoDB table or the dashboard URL.

Tracking

Basically, tracking is nothing more than sending a HTTP request to the API with a set of payload information (currently url, date, name, and a websiteId). Normally you would have an additional non-JS fallback, like an image e.g., but a simple fetch call does the job for now:

fetch(
  'https://lqwyep8qee.execute-api.us-east-1.amazonaws.com/v1/track',
  {
    method: "POST",
    body: JSON.stringify(
      {
        date: new Date().getTime(),
        name: document.title,
        url: location.href,
        website: 'yfFbTv1GslRcIkUsWpa7'
      }
    ),
    headers: new Headers({ "Content-Type": "application/json" })
  }
)

Data Access

An example dashboard to access tracked data is included and deployed to S3. The URL will be displayed after the deploy task. You can access the metrics using basic curl requests as well. Just provide the website and date parameters:

Top Content

The ranking resource scans the DynamoDB for pages with the most hits on a specific date value:

$ > curl https://lqwyep8qee.execute-api.us-east-1.amazonaws.com/dev/ranking?website=yfFbTv1GslRcIkUsWpa7&date=MONTH:2017-08

[
  {
    "name": "Example Website - Serverless Analytics",
    "url": "http://sls-analytics-website.s3-website-us-east-1.amazonaws.com/baz",
    "value": 19
  },
  {
    "name": "Example Website - Serverless Analytics",
    "url": "http://sls-analytics-website.s3-website-us-east-1.amazonaws.com/",
    "value": 10
  },
  {
    "name": "Example Website - Serverless Analytics",
    "url": "http://sls-analytics-website.s3-website-us-east-1.amazonaws.com/bar",
    "value": 4
  }
]

Requests per URL

The series resource scans the DynamoDB for data about a specific url in a given date period.

$ > curl https://lqwyep8qee.execute-api.us-east-1.amazonaws.com/dev/series?website=yfFbTv1GslRcIkUsWpa7&date=HOUR:2017-08-25T13&url=http://sls-analytics-website.s3-website-us-east-1.amazonaws.com/baz

[
  {
    "date": "MINUTE:2017-08-25T13:33",
    "value": 1
  },
  {
    "date": "MINUTE:2017-08-25T13:37",
    "value": 1
  },
  {
    "date": "MINUTE:2017-08-25T13:46",
    "value": 14
  },
  {
    "date": "MINUTE:2017-08-25T13:52",
    "value": 1
  }
]

Date Parameter

The DynamoDB stores the absolute hits number for the dimensions YEAR, MONTH, DATE, HOUR, and MINUTE per default. This may cause lots of write capacities when processing events, but with the serverless-dynamodb-autoscaling plugin DynamoDB will scale the capacities when needed.

All dates are UTC values!

Infrastructure

Infrastructure

License

Feel free to use the code, it's released using the MIT license.

Contribution

You are welcome to contribute to this project! 😘

To make sure you have a pleasant experience, please read the code of conduct. It outlines core values and beliefs and will make working together a happier experience.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].