# notification-dispatcher

This AWS Lambda function is a scheduled job, triggered by a cron expression. Its primary responsibility is to dispatch notifications based on state changes.

On each run, it pulls the latest state from an external service via a GraphQL query, compares this with the last known state stored in DynamoDB, and if an update is detected, triggers a notification.

## 🚀 Local Development

### Prerequisites

* Python 3.13
* A virtual environment tool of your choice (e.g., `venv`, `virtualenv`)
* `make`

### Setup

To set up your local development environment, follow these steps:

1.  **Create a Virtual Environment**: Create and activate a new virtual environment. For example, using Python's built-in `venv`:
    ```bash
    python3.14 -m venv .venv
    source .venv/bin/activate
    ```

2.  **Configure Environment Variables**: This project uses a `.env.shadow` file as a template for required environment variables. Copy it to a new `.env` file and fill in the necessary values.
    ```bash
    cp .env.shadow .env
    # Now, edit the .env file with your local configuration
    ```

3.  **Install Dependencies**: Install all necessary dependencies for development and testing from the `requirements-test.txt` file.
    ```bash
    pip install -r requirements-test.txt
    ```

---

## 🛠️ Available Commands

This project uses a `Makefile` to provide convenient commands for common development tasks.

| Command            | Description                                                              |
| ------------------ | ------------------------------------------------------------------------ |
| `make test`        | Runs the full suite of unit tests using `pytest`.                        |
| `make fix_style`   | Automatically formats the code to fix style issues using `ruff`.         |
| `make check_style` | Checks the code for any style violations using `ruff`.                   |
| `make check_types` | Performs static type checking on the codebase using `mypy`.              |
| `make check_suite` | Runs all checks (`test`, `check_style`, `check_types`) in sequence.      |

---

## ▶️ Running Locally

You can run the lambda function on your local machine in two ways.

### Using Python

To run the function directly with your local Python interpreter:

```bash
python local.py
```

### Using Docker

This method runs the function inside a Docker container that emulates the AWS Lambda environment.

1.  **Start the Service**: Bring the function's container up. This command starts the Lambda runtime emulator, which will then wait for an event.
    ```bash
    docker compose up --build function
    ```

2.  **Invoke the Function**: In a **separate terminal window**, send a test event to the running container using `curl`. This will trigger your function's code to execute.
    ```bash
    curl -X POST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}'
    ```

**Note**: This local setup does **not** support hot reloading. If you make any changes to the code, you will need to stop the service (`Ctrl+C`) and rebuild the image before running it again:
