Microservice for reliably sending emails via an SNS topic using SMTP.
./release.sh
$ terraform init
$ terraform get
$ terraform plan
$ terraform apply
Edit src/config.cfg
to change defaults
Copy src/config-secrets-example.cfg
to src/config-secrets.cfg
and set the SMTP server, port and credentials.
cd src && ./run.sh
- SNS topic triggers the lambda when a message is sent through it. Concurrency is limited to 1 to prevent a lambda being spawned for every email.
- Lambda reads messages off the queue and sends emails using SMTP
- SQS queue has an alarm that fires if the number of available messages is >= 1, which also triggers the lambda (in case the SNS-triggered lambda did not work through all the pending messages)
- Lambda sets alarm state to
OK
before it closes, so that it will be re-triggered if there are still pending messages
Messages that fail to send will be retried automatically by SQS's visibility timeout, up to maxReceiveCount
(at which point they go to the deadletter queue).
Send an email by publishing a message to ion-input-topic
:
{
"action": "send",
"recipient": "???",
"subject": "Test email 1",
"body_text": "This is a plaintext test email",
"body_html": "<html><body><h1>Test email 1</h1><h2>This is a HTML test email</h2></body></html>"
}
Redrive the deadletter queue by publishing:
{
"action": "redrive"
}
- Scaling (i.e., increase lambda concurrency limit)
- Put reserved concurrency into terraform (not currently supported)
- CloudWatch alarms for a large backlog of messages, and messages present in the deadletter queue
- Exponential backoff on failure, instead of just 60 seconds
- Persistent store of emails sent and failed attempts (DynamoDB?)
- Store failure reason with the message in the DLQ