Giter Site home page Giter Site logo

log-bullet-visitors's Introduction

log-bullet-visitors

This is some simple server-side javascript code that I intend to use to track visitors to the various versions of the AF bullet tracking tool:

Privacy

I am only tracking timestamps of visits and which URL was visited (i.e. ea-pods-team or af-vcd, etc). Not going to track IP addresses of visitors, not even user-agent strings.

The primary reason why I created a github repository to manage this lambda function in the first place (as opposed to managing it in AWS console) was to make it very transparent what user information I am tracking. If you don't believe what I'm claiming, you can inspect the code and see for yourself.

Implementation

This was my first time using AWS API Gateway, AWS Lambda, and AWS DynamoDB, so it definitely was a big learning experience for me. If I did anything egregiously wrong/poorly, please submit an issue or otherwise contact me and let me know.

AWS

I started off by creating a lambda function on the AWS. I created a new role for the for the lambda, with write access to CloudWatch Logs (don't think I'm using this) and read/write access to DynamoDB (definitely using this). I think I ended up using a template that included some boilerplate code for DynamoDB access.

Next I went to the DynamoDB site and created a created a table with a single partition key. I created some test rows so I could check if GET/POST was working in the lambda function.

Back to the lambda function: I set request headers to enable CORS (see the code), but it wasn't working as expected for the boilerplate code. After some trial and error, I managed to get it working via use of routes the AWS API Gateway and CORS handled manually in the lambda function.

The API gateway was initially configured for the lambda function after I created it. The gateway has some CORS capabilities, but I could not get it to work, I was getting errors like "http not ok" and the typical CORS error messages. Instead of using API Gateway CORS, I turned it off and instead replaced the ANY route with three allowed routes: OPTIONS, GET, and POST. I set all three to routes to point to the lambda function, which seems redundant, but was actually important because otherwise I couldn't easily distinguish between GET, POST, and OPTIONS requests in my lambda function.

Once I got that working, it was relatively easy to set up the DynamoDB getting and setting through some googling and reading the dynamodb documentclient documentation

Github

I primarily used the guide here to figure out how to integrate the AWS lambda function with github. I had to run npm init and npm install aws-sdk in order to auto-generate package.json and package-lock.json, but otherwise went very smoothly. For the AWS credentials, I created a new user with only lambda permissions, trying to follow least priviledge principles.

log-bullet-visitors's People

Contributors

ckhordiasma avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.