2.1.2 • Published 8 years ago
pidash-email-npm-module v2.1.2
PI dashboard email NPM module
Email library for the PI Dashboard's mailer jobs and admin site. (Email Constructor, Email Sender, and Admin site)
Setup
The module expects the following environment variables to be defined:
AWS_REGIONEMAIL_BATCH_DYNAMODB(ifEmail#createorEmail#getBatchesare used)EMAIL_METADATA_DYNAMODBEMAIL_BODY_DYNAMODB- For
Email#send:EMAIL_SENDER_LAMBDAEMAIL_SENDER_QUEUEEMAIL_SENDER_SERVICEEMAIL_SENDER_CLUSTEREMAIL_SENDER_TASKNAME
- For
Email#construct:EMAIL_CONSTRUCTOR_LAMBDAEMAIL_CONSTRUCTOR_QUEUEEMAIL_CONSTRUCTOR_SERVICEEMAIL_CONSTRUCTOR_CLUSTEREMAIL_CONSTRUCTOR_TASKNAME
Include this in your project by adding:
"dependencies": {
"pidash-email": "raisdev/pidash-email-npm-module#v1.0.8"
}Testing/linting
Run tests with npm test, and linting with npm run lint.
Make sure that you have all the dependencies installed.
Architecture
When we want to create an email, we go through the following process:
Create emails on admin site -> (pushes to DynamoDB)
Click 'build' on admin site ->
Launches a lambda for each email, which:
adds an item to an SQS queue
creates (or updates) a AWS ECS service ->
The service starts up some tasks, each of which:
Pulls an email off the queue(or quits the service if the queue is empty)
Builds an email
Updates its status
Uploads the complete email to DynamoDB
The person waiting on the admin site can reload the page and
sees the email's status change (from 'generating' to 'generated')
they can review the email.
Click on 'send' on admin site ->
Launches (the same) lambda for each email, which:
adds an item to an SQS queue
creates (or updates) a AWS service ->
Each of the service's tasks:
Pulls an email off the queue (or quits the service if the queue is empty)
Sends the email (after some basic validating)
Updates the email's statusOne of the unexpected side effects is that, to change the ECS service, you need to delete the existing ECS services and then modify the Lambda to use the new service.
Amazon has put together an example repository (Lambda ECS Worker Pattern) that has a somewhat similar architecture.
AWS resources
Lambda
- emailLambda (ECS & SQS permissions)
SQS
- emailSenderQueue
- emailConstructorQueue
ECS (each of these need to be in some cluster)
- some-admin-service
- some-admin-task
- admin container
- some-admin-task
- emailConstructors service
- constructEmail task
- emailConstructor container
- constructEmail task
- emailSenders service
- sendEmail task
- emailSender container
- sendEmail task
DynamoDB
- email_batch (batch, date)
- email_body (netid, date, batch, status)
- email_metadata (netid, date, body)
- pidash-admin-sessions (setup by admin)
- pidash-admin-users (setup by admin
SES
- fromEmailAddress@cornell.edu Email Address Identity
IAM
- ECS instance role
- DynamoDB full access
- SES full access
- EC2 Container Service for EC2
- SQS full access (reading from queue, removing from queue)
- Lambda Role
- ECS full access (create, update, describe, etc...)
- SQS full access (only uses adding to queue)