Skip to content

FridgeFinder/CFM_User_Rewards

Repository files navigation

FridgeFinder User Rewards Service

GitHub contributors GitHub commit activity (dev)

CFM User Rewards Service

Async, event-driven service that awards points and maintains action-stat counters when users performs actions.


Architecture Overview

Producer services (EventBridge events)
        │
        ▼
EventBridge Bus  ─────► EventBridge Rules
                                │
                                ▼
                  UserRewardsConsumerFunction
                     │            │
                     ▼            ▼
              UserPointsHistory  UserActionStats

Pre-Requisites

  1. 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)
  2. 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 supported when running sam build --use-container make sure your SAM CLI version is up to date
  3. Python 3 - Install Python 3
  4. Docker - Install Docker

Setup Local Database Connection

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

  1. Start a local DynamoDB service

    $ docker compose up
    # OR if you want to run it in the background:
    $ docker compose up -d
  2. Create tables

    $ ./local_scripts/create_local_dynamodb_tables.py

Local Setup

# 1. Create a virtual environment
python3 -m venv .venv
source .venv/bin/activate

# 2. Install dependencies
make install

Running Unit Tests

# 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

SAM Build & Local Invoke

# Build Lambda package (resolves dependencies)
make build

# Invoke locally with a FridgeReportUpdated event (both reports present)
make invoke-fridge-report-updated

# Invoke locally with a FridgeReportUpdated event (no previous report)
make invoke-fridge-report-updated-new-only

# Use sam local invoke directly with any event file
sam local invoke UserRewardsConsumerFunction \
    --event events/status_update_created.json \
    --env-vars env.local.json

Deploy to AWS

# First-time guided deploy (creates samconfig.toml)
sam deploy --guided

# Subsequent deploys
make deploy

# Override environment
make deploy ENV=staging

License

See LICENSE.

About

User Rewards

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors