# Focus Group Email Campaign — Implementation Document

**Date**: June 12, 2026
**AWS Account**: 489176460030 (tbi-prod)
**Region**: ca-central-1

---

## Architecture

```
┌─────────────────┐     ┌──────────────┐     ┌─────────────────┐
│  CSV (S3)       │────▶│   Lambda     │────▶│   Amazon SES    │────▶ Recipients
│  recipients.csv │     │  (Python 3.12)│     │  Bulk Email API │
└─────────────────┘     └──────┬───────┘     └────────┬────────┘
                               │                      │
                               ▼                      ▼
                        ┌──────────────┐     ┌─────────────────┐
                        │ SES Template │     │   SNS Topic     │
                        │ (HTML + vars)│     │ (Bounce/Complaint)│
                        └──────────────┘     └────────┬────────┘
                                                      │
                                                      ▼
                                              Philip.Aouad@travelbrands.com
```

---

## AWS Resources Created

| Resource | Name/ARN | Purpose |
|----------|----------|---------|
| Lambda Function | `tbi-redtag-focus-group-campaign` | Sends bulk emails |
| IAM Role | `tbi-redtag-focus-group-lambda-role` | Lambda execution permissions |
| S3 Bucket | `tbi-redtag-focus-group-campaign` | Stores recipient CSV files |
| SES Template | `redtag-focus-group-invite` | HTML email template with dynamic vars |
| SES Config Set | `focus-group-campaign` | Routes bounce/complaint events |
| SNS Topic | `ses-focus-group-bounces` | Delivers bounce/complaint notifications |

---

## Lambda Event Parameters

| Parameter | Required | Description | Example |
|-----------|----------|-------------|---------|
| `subject` | ✅ | Email subject line | `"Hey, {{name}}! Test the new redtag.ca app & get rewarded"` |
| `deadline` | ✅ | T&C deadline shown in email body | `"July 19th, 2026"` |
| `bounce_email` | ✅ | Bounce/complaint alert recipient | `"Philip.Aouad@travelbrands.com"` |
| `csv_s3_bucket` | ✅ | S3 bucket with recipient CSV | `"tbi-redtag-focus-group-campaign"` |
| `csv_s3_key` | ✅ | S3 key for CSV file | `"recipients.csv"` |
| `sender` | ❌ | From address (default: `redtag.ca <noreply@redtag.ca>`) | `"redtag.ca <noreply@redtag.ca>"` |
| `template_name` | ❌ | SES template (default: `redtag-focus-group-invite`) | — |
| `batch_size` | ❌ | Emails per batch (default: 50) | `50` |

---

## Template Dynamic Variables

| Variable | Location | Description |
|----------|----------|-------------|
| `{{name}}` | Email body greeting | Recipient's first name from CSV |
| `{{deadline}}` | Terms & Conditions section | Completion deadline date |

---

## CSV Format

```csv
name,email
John,john@example.com
Jane,jane@example.com
```

---

## SES Configuration Details

| Setting | Value |
|---------|-------|
| Sender Domain | `redtag.ca` (verified, DKIM enabled) |
| Sender Email | `noreply@redtag.ca` (verified) |
| Production Access | ✅ Enabled |
| Daily Send Limit | 50,000 |
| Max Send Rate | 14/second |
| Suppression | Auto-suppress bounces + complaints |
| VDM/Engagement Metrics | Enabled |

---

## Batch Processing

- **Batch size**: 50 emails per API call
- **Rate delay**: 4 seconds between batches
- **2,000 recipients**: ~40 batches × 4s = ~2.5 minutes total
- **Lambda timeout**: 5 minutes (300s)
- **Retry**: SES handles individual message retries internally

---

## Monitoring & Tracking

### Bounce/Complaint Alerts
- SNS topic `ses-focus-group-bounces` → email notification
- SES auto-suppression prevents re-sending to bounced addresses

### Delivery Metrics
- SES VDM Dashboard: https://ca-central-1.console.aws.amazon.com/ses/home?region=ca-central-1#/vdm
- Configuration set metrics in SES console under `focus-group-campaign`

### Lambda Logs
- CloudWatch: `/aws/lambda/tbi-redtag-focus-group-campaign`

---

## Files

```
~/Desktop/focus_group_campaign/
├── lambda_function.py          # Lambda source code
├── deploy.sh                   # Infrastructure deployment script
├── recipients.csv              # Sample CSV template
└── send_campaign.py            # Local CLI alternative (optional)

~/Desktop/focus_group_email_template.html   # HTML email template source
```

---

## Updating the Email Template

1. Edit `~/Desktop/focus_group_email_template.html`
2. Run:
```bash
HTML_CONTENT=$(cat ~/Desktop/focus_group_email_template.html | python3 -c "import sys,json; print(json.dumps(sys.stdin.read()))")
aws sesv2 delete-email-template --template-name redtag-focus-group-invite --region ca-central-1 --profile tbi-prod
aws sesv2 create-email-template \
  --template-name redtag-focus-group-invite \
  --template-content "{\"Subject\":\"You are invited to test the redtag.ca app\",\"Html\":$HTML_CONTENT,\"Text\":\"Hey {{name}},\n\nYou are invited to test the redtag.ca app.\nComplete by {{deadline}} to qualify.\"}" \
  --region ca-central-1 --profile tbi-prod
```

---

## Updating the Lambda Code

```bash
cd /tmp && zip -j function.zip ~/Desktop/focus_group_campaign/lambda_function.py
aws lambda update-function-code \
  --function-name tbi-redtag-focus-group-campaign \
  --zip-file fileb://function.zip \
  --region ca-central-1 --profile tbi-prod
```

---

## Security

- S3 bucket has public access blocked
- IAM role is least-privilege (SES send, S3 read, SNS create/subscribe, CloudWatch logs)
- No secrets stored in Lambda — all config passed via event payload
- Sender domain verified with DKIM signing (RSA 2048-bit)
