Async, event-driven service that awards points and maintains action-stat counters when users performs actions.
Producer services (EventBridge events)
│
▼
EventBridge Bus ─────► EventBridge Rules
│
┌──────┴──────────────────┐
▼ ▼
UserRewardsConsumerFunction UserDeletionHandlerFunction
│ │ │
▼ ▼ (deletes all
UserPointsHistory UserActionStats reward data)
HTTP API (GET) ─────► UserHttpApi (API Gateway)
│
▼
GetUserActionStatsFunction
(reads UserActionStats)
- AWS CLI - Install the AWS CLI
- You DO NOT have to create an AWS account to use AWS CLI for this project, skip these steps if you don't want to create an AWS account
- AWS CLI looks for credentials when using it, but doesn't validate. So will need to set some fake one. But the region name matters, use any valid region name.
$ aws configure $ AWS Access Key ID: [ANYTHING YOU WANT] $ AWS Secret Access Key: [ANYTHING YOUR HEART DESIRES] $ Default region nam: us-east-1 $ Default output format [None]: (YOU CAN SKIP)
- SAM CLI - Install the SAM CLI
- You DO NOT need to create an aws account to use SAM CLI for this project, skip these steps if you don't want to create an aws account
- Note: if you are getting the following error:
runtime is not supportedwhen runningsam build --use-containermake sure your SAM CLI version is up to date
- Python 3 - Install Python 3
- Docker - Install Docker
Guide that was used: https://betterprogramming.pub/how-to-deploy-a-local-serverless-application-with-aws-sam-b7b314c3048c
Follow these steps to get Dynamodb running locally
-
Start a local DynamoDB service
$ docker compose up # OR if you want to run it in the background: $ docker compose up -d -
Create tables
$ ./local_scripts/create_local_dynamodb_tables.py
# 1. Create a virtual environment
python3 -m venv .venv
source .venv/bin/activate
# 2. Install dependencies
make install# Run all tests with verbose output
make test
# Run with coverage report (generates htmlcov/)
make test-cov
# Run a single test file
PYTHONPATH=functions/fridge_report_consumer pytest tests/test_rules.py -v# Build Lambda package (resolves dependencies)
make build# FridgeReportUpdated event (both reports present)
make invoke-fridge-report-updated
# FridgeReportUpdated event (no previous report)
make invoke-fridge-report-updated-new-onlymake invoke-get-user-action-statsmake invoke-user-deletedSAM can spin up a local HTTP server that emulates API Gateway, letting you hit endpoints with curl or a browser.
# Start the local API (binds to http://127.0.0.1:3000 by default)
sam local start-api \
--parameter-overrides ParameterKey=DeploymentTarget,ParameterValue=local ParameterKey=Environment,ParameterValue=dev \
--docker-network cfm-networkOnce running, the available endpoints are:
| Method | Path | Function |
|---|---|---|
GET |
http://127.0.0.1:3000/hello |
HelloWorldFunction |
GET |
http://127.0.0.1:3000/v1/user-action-stats/{userId} |
GetUserActionStatsFunction |
Example requests:
# Health check
curl http://127.0.0.1:3000/hello
# Get action stats for a user
curl http://127.0.0.1:3000/v1/user-action-stats/user9Note: Make sure
docker compose upis running first so the local DynamoDB tables are available.
The spec lives at docs/openapi.yaml and is published to GitHub Pages automatically on every push to main that touches docs/.
View docs online: https://<your-org>.github.io/<repo-name>/
Serve the docs/ folder with any static file server — the page loads Swagger UI from a CDN and renders the spec in the browser.
# Python (no install needed)
python3 -m http.server 8080 --directory docs
# then open http://localhost:8080All deploy configuration lives in samconfig.toml. Fill in any <REPLACE_ME> placeholders for staging/prod before deploying.
# Deploy to dev (default)
make deploy
# Deploy to staging or prod
make deploy ENV=staging
make deploy ENV=prod
# First-time only — validate the template before deploying
sam validate --config-env devSee LICENSE.