Skip to content

A really simple Flask web app - deployed as AWS Lamba function - to record the presence of students in a study room.

License

Notifications You must be signed in to change notification settings

niccolozanotti/people-tracker-flask-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Real-time occupants of a public room API

This project is a Flask-based API for tracking the registration and unregistration of people, along with logging their actions. The API is deployed on AWS Lambda, thus serverless, using the aws-wsgi package,

Features

  • Register a Person: Add a person to the current list of occupants.
  • Unregister a Person: Remove a person from the current list of occupants.
  • Status Check: Get the current status of the location, including a list of occupants and their count.
  • Logging: Actions are logged with timestamps and stored in an S3 bucket.

Endpoints

1. Register a Person

  • URL: /people/register
  • Method: POST
  • Request Body:
    {
      "name": "Person Name"
    }
  • Response
    • 200 OK
      {
        "status": "registered",
        "occupants": ["Person Name", ...]
      }
    • 400 Bad request
       {
         "error": "name is required",
       }

2. Unregister a Person

  • URL: /people/unregister
  • Method: POST
  • Request Body:
    {
      "name": "Person Name"
    }
  • Response
    • 200 OK
      {
        "status": "unregistered",
        "occupants": ["Remaining Occupants", ...]
      }
    • 400 Bad request
       {
         "error": "name is required",
       }

3. Get Status

  • URL: /people/status
  • Method: GET
  • Response
    • 200 OK
      {
        "status": "open" or "closed",
        "occupants": ["Person Name", ...],
        "count": number
      }

AWS S3 Logging

  • S3 Bucket: The log files are stored in an S3 bucket named ugo-people-tracker.
  • Log Format: Each log entry contains the date, time, name of the person, and the action (register or unregister).
  • File Naming: Logs are saved daily with the filename format YYYY-MM-DD-logs.csv.

Deployment

This application is deployed on AWS Lambda using aws-wsgi. Below are the deployment steps:

Prerequisites

  1. Set Up AWS Lambda:
    • Create a new Lambda function in AWS Console.
    • the Python 3.x runtime.
    • Ensure the Lambda function has a role with permissions to access S3.
  2. Package the Application:
    • Zip the application files including lambda_function.py and dependencies.
  3. Upload and Deploy:
    • Upload the zipped package to AWS Lambda.
    • Set the handler to lambda_function.lambda_handler.
  4. API Gateway Setup:
    • Create an API Gateway to expose the Lambda function as an HTTP API.
    • Configure CORS settings if needed.

Local Development

For local testing and development, you can run the Flask application using the built-in server:

python lambda_function.py

The application will be accessible at http://127.0.0.1:5000/.

Notes

  • Ensure your Lambda function has the necessary permissions to read and write to the specified S3 bucket.

License

This project is licensed under the MIT License.

About

A really simple Flask web app - deployed as AWS Lamba function - to record the presence of students in a study room.

Resources

License

Stars

Watchers

Forks

Languages