Update tech_docs/AWS_Lambda_for_Amazon_Connect_Survey_Processing.md
This commit is contained in:
@@ -1,3 +1,55 @@
|
|||||||
|
Below is a **concise reaction** to the very thorough peer review you provided, plus a **“next-step” checklist** that distills everything into one developer-day of focused refactoring. Think of it as the TL;DR that actually fits on a sticky-note.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. High-level Reaction
|
||||||
|
Your review is excellent—every major pain point is called out and backed by concrete examples.
|
||||||
|
The only thing I’d add is **risk priority**:
|
||||||
|
- **P0 (can page at 3 a.m.)** – silent duplicate writes, unbounded SES calls.
|
||||||
|
- **P1 (tech-debt)** – monolith, globals, hard-codes.
|
||||||
|
- **P2 (polish)** – PEP-8, type hints, tests.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. One-Day Refactor Plan
|
||||||
|
|
||||||
|
| Step | Task | Impact | LOC Change |
|
||||||
|
|------|------|--------|------------|
|
||||||
|
| 1 | Replace all `print()` with `logging.getLogger(__name__)` | Observability | ~25 |
|
||||||
|
| 2 | Extract `decode_kinesis_record` + `validate_survey` + `store_survey` + `enrich_agent` | Testability | +120 / –80 |
|
||||||
|
| 3 | Move constants to top-level `Config` dataclass | Maintainability | +30 |
|
||||||
|
| 4 | Add `ConditionExpression="attribute_not_exists(ContactID)"` on `put_item` | Idempotency | +1 |
|
||||||
|
| 5 | Replace global AWS clients with a `Clients` dataclass injected via handler arg | Unit tests | +40 |
|
||||||
|
| 6 | Run `black`, `isort`, `flake8`, add `mypy --strict` baseline | Style | auto |
|
||||||
|
| 7 | Add one happy-path unit test with `moto` and `pytest` | Confidence | +60 |
|
||||||
|
|
||||||
|
Total effort ≈ **4–6 hrs** if you TDD the new functions first.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. Micro-gotchas to Fix While You’re There
|
||||||
|
- Remove duplicate key `"statuscode"` in response dict.
|
||||||
|
- `str(data)` already handles `str` and non-`str`; delete the verbose ternary.
|
||||||
|
- `ZoneInfo(timeZone)` → `ZoneInfo(os.getenv("TZ", "America/New_York"))`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Quick Safety Net
|
||||||
|
Add this **top-level alarm** in CloudWatch if you don’t already have it:
|
||||||
|
|
||||||
|
```
|
||||||
|
MetricName = "Lambda Errors"
|
||||||
|
Namespace = "AWS/Lambda"
|
||||||
|
Dimensions = [FunctionName = <this-lambda>]
|
||||||
|
Threshold = 1
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Land the seven bullets above and you’ll have a **B+ production Lambda** that is testable, observable, and idempotent—without a full rewrite.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
### **Code Review: AWS Lambda for Amazon Connect Survey Processing**
|
### **Code Review: AWS Lambda for Amazon Connect Survey Processing**
|
||||||
|
|
||||||
This document provides a peer code review of the provided Python script for an AWS Lambda function.
|
This document provides a peer code review of the provided Python script for an AWS Lambda function.
|
||||||
|
|||||||
Reference in New Issue
Block a user