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,
- 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.
- 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", }
- 200 OK
- 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", }
- 200 OK
- URL:
/people/status
- Method:
GET
- Response
- 200 OK
{ "status": "open" or "closed", "occupants": ["Person Name", ...], "count": number }
- 200 OK
- 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.
This application is deployed on AWS Lambda using aws-wsgi. Below are the deployment steps:
- 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.
- Package the Application:
- Zip the application files including lambda_function.py and dependencies.
- Upload and Deploy:
- Upload the zipped package to AWS Lambda.
- Set the handler to lambda_function.lambda_handler.
- API Gateway Setup:
- Create an API Gateway to expose the Lambda function as an HTTP API.
- Configure CORS settings if needed.
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/
.
- Ensure your Lambda function has the necessary permissions to read and write to the specified S3 bucket.
This project is licensed under the MIT License.