workorder-ingest/README.md

71 lines
2.1 KiB
Markdown
Raw Normal View History

# Work Order Ingest
AWS serverless pipeline that ingests work order emails from Amazon's APM system (Hexagon EAM / HxGN SmartCloud), parses them with Claude AI, and stores structured data in DynamoDB.
## Architecture
```
Email (amazon@seahavenind.com)
→ Gmail filter (from: noreply@hxgnsmartcloud.com)
→ Forwards to apm@int.seahaven.com (SES)
→ S3 bucket (raw email storage)
→ Lambda (email processor)
→ Claude Haiku (structured extraction)
→ DynamoDB (WorkOrders + WorkOrderComments)
```
## Components
- **Email Processor Lambda** (`lambdas/email_processor/`) - Parses raw emails, sends to Claude for structured extraction, writes to DynamoDB
- **Web UI Lambda** (`lambdas/web_ui/`) - Server-rendered HTML dashboard for viewing work orders and event history
- **CDK Stack** (`cdk/`) - Infrastructure as code for all AWS resources
- **Shared Models** (`shared/`) - Data models for work orders, comments, and parsed emails
## Extracted Fields
- Work Order ID, Description, Status
- Site Code, Building, Address
- Severity, Priority
- Due Date, Date Reported, Scheduled Start
- Assigned To, Commenter, Comment Text
- Record Type (new_work_order, update, comment, cancellation)
## DynamoDB Tables
- **WorkOrders** - Latest state of each work order (PK: `work_order_id`)
- **WorkOrderComments** - Event history per work order (PK: `work_order_id`, SK: `comment_id`)
## Local Testing
```bash
python3 -m venv .venv
source .venv/bin/activate
pip install anthropic boto3
export ANTHROPIC_API_KEY=sk-ant-...
python test_local.py
```
## Deployment
```bash
cd cdk
pip install aws-cdk-lib constructs
npx cdk bootstrap # first time only
npx cdk deploy
```
After deploying, store your Anthropic API key in Secrets Manager:
```bash
aws secretsmanager put-secret-value \
--secret-id "workorder-ingest/anthropic-api-key" \
--secret-string "sk-ant-..." \
--region us-east-1
```
## SES Configuration
- Domain: `int.seahaven.com` (MX record pointing to `inbound-smtp.us-east-1.amazonaws.com`)
- Receipt Rule Set: `INBOUND_MAIL`
- Recipient: `apm@int.seahaven.com`