df20
Overview
This is the code that handles the email ingest/processing for the Hey Email Research Labs (HERL) Dumpsterfire. All ingest, scanning, filtering, processing, and moderation are handled here.
You will need:
- AWS account
- Domain names
- A Raspberry Pi with node-red
- Familiarity with Terraform, AWS Lambda, SES, SQS, ruby, node.js, node-red, bash, and jq.
- A lot of patience.
Details
-
Customer emails
dumpsterfire@hey.com
. -
AWS SES receives email.
- SES checks for spam/dkim/spf
- SES sends headers to
email_filter
js lambda. - SES drops email into s3 bucket
s3://dumpsterfire-bucket/inbound/
-
S3 fires off SNS notification when email hits
/inbound
. -
SNS triggers
processor
ruby lambda. This moves the email between 4 states, triggering a S3->SNS notification each time:- /inbound -> lambda screens email for content size (<5MB)
- /screened -> lambda formats email body for printing
- /print -> lambda publishes message to SQS screener queue with job data, and another SQS queue for initial marketing response.
- /completed, but that happens in step 8.
-
SQS triggers
screener
ruby lambda. This reads thes3://dumpsterfire-rules/rules.json
file and filters jobs accordingly, dumping the ones that pass into the print queue. -
Raspberry Pi pulls message off SQS print queue for approval; either sending to the moderated queue or deleting the job from the queue.
-
The print loop pulls messages off the moderated queues (Normal, VIP, or Special), and prints/burns them.
-
Rasberry Pi puts message on SQS Queue when complete.
-
SQS triggers
cleanup
lambda. This puts a message on another SQS queue for final email response, and moves the file tos3://dumpsterfire-bucket/completed/
. -
S3 fires off SNS notification when email hits
/completed
9 SNS triggersprocessor
ruby lambda, which updatess3://dumpsterfire-cloudfront/stats.json
.
Infrastructure
Terraform bits are under terraform
, ruby lambda code is under lambdas/processor
, and node-red flows are under node-red
.
Appropriately named dumpster
profile needed in your ~/.aws/config
/~/.aws/credentials
for this to work.
Generate a new lambda package:
for lambda in processor cleanup screener; do
pushd lambdas/$lambda
rake package
mv *.zip ../../terraform/production/
popd
done
pushd terraform/production
terraform apply -auto-approve
popd
Email Filter
It's a javascript lambda because that's the only lambda runtime that supports callbacks, which are required for SES Actions to work correctly. (AFAICT)
pushd lambdas/email_filter
zip -r email_filter.zip index.js index-async.js node_modules package.json package-lock.json
mv email_filter.zip ../../terraform/production/
popd
pushd terraform/production
terraform apply -auto-approve
popd
Hey Marketing Auto-reply
This is a systemd service running on a node authorized to send email from the hey domain. The service file is /etc/systemd/system/reply.service
, and it runs /path/to/hey-marketing-reply/reply.sh
. The script relies on the aws
commands and credentials in my home directory.
To update, copy the new script into /path/to/hey-marketing-reply/reply.sh
, fix ownership if needed, and run sudo systemctl restart reply.service
.
Logs are available via sudo journalctl -f -u reply.service
.
Same for the hey-marketing-complete-reply
mailer.