|
| 1 | +# Rust Lambda Assignment: Action Filter |
| 2 | + |
| 3 | +This repository contains a **broken** AWS Lambda written in Rust. Your task is to debug and fix it so that it compiles, runs locally, and produces correct results. |
| 4 | + |
| 5 | +## 📋 Scenario |
| 6 | + |
| 7 | +The Lambda receives a JSON list of **actions**, each with: |
| 8 | + |
| 9 | +* `entity_id` — string identifier |
| 10 | +* `last_action_time` — ISO‑8601 timestamp |
| 11 | +* `next_action_time` — ISO‑8601 timestamp |
| 12 | +* `priority` — `"high"` or `"low"` |
| 13 | + |
| 14 | +### Business Rules |
| 15 | + |
| 16 | +1. **At most one** action per `entity_id`. |
| 17 | +2. Only include actions where **`next_action_time` is within 90 days** of *today*. |
| 18 | +3. **High‑priority** actions should appear **first** in the output. |
| 19 | +4. Skip any action where **`last_action_time` is < 7 days ago**. |
| 20 | + |
| 21 | +Unfortunately, the code has **three deliberate problems**: |
| 22 | + |
| 23 | +| Type | What you’ll see | |
| 24 | +|------|-----------------| |
| 25 | +| Compilation error | Lifetime/key mismatch in a `HashMap` declaration | |
| 26 | +| Runtime panic | Timestamp math can panic with certain input | |
| 27 | +| Logic bug | Priority sorting is wrong (`"high"` can end up after `"low"`) | |
| 28 | + |
| 29 | +## 🛠 Getting Started |
| 30 | + |
| 31 | +1. **Install Rust** (stable) and [cargo‑lambda](https://github.com/cargo-lambda/cargo-lambda): |
| 32 | + |
| 33 | + ```bash |
| 34 | + rustup update stable |
| 35 | + cargo install cargo-lambda |
| 36 | + ``` |
| 37 | + |
| 38 | +2. **Run the Lambda locally** with sample data: |
| 39 | + |
| 40 | + ```bash |
| 41 | + cargo lambda invoke --data-file testdata/sample-input.json |
| 42 | + ``` |
| 43 | + |
| 44 | + You should observe a compilation error first. Fix it, then re‑run to expose the panic and logic bug. |
| 45 | + |
| 46 | +3. **Fix all three problems** so the Lambda prints a correct, filtered list. |
| 47 | + |
| 48 | +## ✅ Acceptance Criteria |
| 49 | + |
| 50 | +* The project **compiles cleanly** (`cargo check` passes). |
| 51 | +* `cargo lambda invoke …` returns the correct, filtered JSON. |
| 52 | +* No panics for well‑formed input. |
| 53 | +* Clear, idiomatic Rust code with proper error handling and logging (`tracing` or `log` welcome). |
| 54 | + |
| 55 | +## 🧪 Optional Stretch Goals |
| 56 | + |
| 57 | +* Add unit tests in `tests/`. |
| 58 | +* Improve error messages and JSON schema validation. |
| 59 | +* Propose a CDK deploy step or GitHub Actions workflow. |
| 60 | + |
| 61 | +Good luck — happy debugging! |
0 commit comments