Git Product home page Git Product logo

gym-class-tracker's Introduction

Gym class tracker

The gym class tracker is a very simple application that can setup a "tracker query" to the REST of a Gym for the availability of a class.

c4-context-diagram

The application is built using a simple serverless setup with Lambda, DynamoDB, SNS and EventBridge Scheduler.

aws-architecture

The "tracker query" and its current state are stored in DynamoDB. A Lambda function contains the logic to call the gym API and check if the class of interest is currently available to be booked. For any status changes or errors, a notification is sent to a (fixed) user using SNS. The Lambda Function is called regularly using an Event Bridge Scheduler

sequence-diagram

Project structure

This project uses the AWS Serverless Application Model (SAM) and was built using the AWS Toolkit in VSCode.

Folder structure:

  • execute-check - Code for the Lambda function executing a check against the gym's API.
  • events - Invocation events that you can use to invoke the function.
  • tests - Unit tests for the application code.
  • template.yaml - A template that defines all the application's AWS resources.
  • docs - Diagrams for documentation
  • proof-of-concept - First draft of the Lambda function which was originally manually deployed

Deploy the sample application

To build and deploy the application for the first time, run the following in your shell:

sam build --use-container

# this will guide you through installation and prompt for the stack name, AWS region and capability to create IAM roles (to create/modifycIAM roles, the `CAPABILITY_IAM` value for `capabilities` must be set). Arguments can be savet to samconfig.toml
sam deploy --guided

After the first deployment, these comments can be used to deploy changes:

sam build 
sam deploy --parameter-overrides EmailAddress=[enter email address to send notifications] 

Use the SAM CLI to build and test locally

Build your application with the sam build --use-container command.

# build: installs dependencies and creates a deployment package in .aws-sam/build
sam build --use-container

Run functions locally and invoke them with the sam local invoke command. Test events are included in the events folder in this project.

sam local invoke ExecuteCheckFunction --event events/empty-call.json

Fetch, tail, and filter Lambda function logs

Read logfiles from the deployed Lambda function using the SAM CLI:

sam logs -n ExecuteCheckFunction --stack-name gym-class-tracker --tail

Create a tracker query

Example for a query in DynamoDB

{
  "partition-key": {
    "S": "query-1"
  },
  "sort-key": {
    "S": "1"
  },
  "entity-name": {
    "S": "check-query"
  },
  "active-status": {
    "S": "1"
  },
  "availability-status": {
    "S": "Unknown"
  },
  "center-id": {
    "S": "23"
  },
  "course-title": {
    "S": "BODYPUMP® 55'"
  },
  "daytime-id": {
    "S": "4"
  },
  "weekday-id": {
    "S": "3"
  }
}

Variables

center-id:

  • 23 = Zürich Altstetten

daytime-id:

  • 1 = morning
  • 2 = noon
  • 3 = afternoon
  • 4 = evening

weekday-id:

  • 1 = Monday
  • ...
  • 7 = Sunday

Cleanup

Delete the deployed application again:

sam delete gym-class-tracker

Resources

Improvement options

  • Split app.py into different files: separate for DynamoDB, API handling and SNS
  • Add tests for separate areas
  • build additional Lambda CreateTrackerQuery that writes a tracker-query into DynamoDB
  • build API Gateway for CreateTrackerQuery
  • Secure API Gateway
  • Enable different email addresses (maybe move away from SNS for this?)

gym-class-tracker's People

Contributors

iris-hunkeler avatar

Stargazers

 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.