The outbound email service de-queues requests made by the API and sends email notifications.
- It can be installed as either a lambda function or sandbox
- It can send email using the sendgrid service or the NodeMailer npm module.
- It supports AWS SQS and RabbitMQ.
- Install the dev_tools toolkit here.
- Make sure you can access the CodeStream network via the VPN.
- Review how we manage our server configurations.
- Make sure your API and mongo sandboxes are running on their default development ports.
- The default configuration will use AWS SQS, sendgrid and run as as node sandbox.
- Choose a sandbox name (for exmaple, mailout) and install the sandbox:
$ dt-new-sandbox -yCD -t cs_mailout -n mailout - Load your sandbox
$ dt-load mailout - Create a playground named mailout (different than the sandbox):
$ dt-sb-create-playground -t $CS_OUTBOUND_EMAIL_TOP/sandbox/playgrounds/default.template - Kill your shell and start a new one. Load your playground and start up your service
$ dt-load-playground mailout $ cs_outbound_email-service start - To start in the foreground without clustering:
$ $CS_OUTBOUND_EMAIL_TOP/bin/outbound_email_server.js --one_worker
If you run the service as a lambda function, make sure your VPN is up. The lambda function needs to connect to your mongo db.
Execute these commands in your sandbox to install a lambda function called local_{DT_USER}_outboundEmail.
$ . sandbox/lambda-configs/lambda-defaults.sh # prepare sandbox for lambda deployment
$ npm run pack # zip the sandbox & config to out/outbound-email.zip
$ npm run lambda:config # create the lambda function config file in out/outbound-email.lambda.json
$ npm run lambda:install # create the lambda function and sqs trigger
As the outbound_email sandbox will change over time, as may your VPN connection, it is not wise to keep your lambda development function up and running indefinitely. It will eventually stop working properly and costs money. So when you're done doing your scope of work, uninstall your lambda function.
You can see the lambda functions with:
$ dt-aws-lamnda -a list-funcs
In a nutshell, the development lifecycle looks like this:
- Modify your API server so it queues outbound email events
- Update your outbound_email sandbox and install your lambda function
- During development, update your function's code or environment variables as often as is needed.
- Push your changes. TeamCity will handle publishing them across the various environments.
- When you're done, modifued your API server so it no longer puts outbound email events on the queue.
- Uninstall your lambda function.
Use the npm scripts below to do the work of installing, uninstalling, updating, etc..
Build / Create asset (out/outbound-email.zip)
$ npm run pack
Update the Lambda function in AWS with the latest build
$ npm run lambda:update
Perform both abovemented tasks at once
$ npm run reupdate
Create the Lamda function definition (../out/outbound-email.lambda.json)
$ npm run lambda:config
Install the lambda function and a trigger on the SQS queue
$ npm run lambda:install
Uninstall the lambda function and trigger (do this when you're done developing). Note that uninstalling a lambda function and its triggers takes time to completely flush in AWS so you should wait a little bit before you re-install it.
$ npm run lambda:uninstall
Update the Lambda function environment variables (prerequisite - lamda:config)
$ npm run lambda:update_env
Clean the repo
$ npm run clean
Note that the default behavior for your api server is to disable
adding email events to the SQS queue so you need to enable that. In your api
sandbox run unset CS_API_SUPPRESS_EMAIL and restart the service.
This command will drop a registration email event in the SQS queue for your outbound email service to process (the email address must be unique each time your run it).
cs_outbound_email-ping [email protected]
This client app will poll your SQS queue and process the event (no lambda function used)
cd src && ./LambdaTest.js
Once your lambda function and trigger are installed, they will process the registration email event your api service queued above from the ping.