A serverless microservice for sending SMS and email notifications via AWS Lambda.
FLC Notify Service is a notification microservice built for First Love Center projects. It provides a secure API to send SMS messages and emails through a unified interface.
- Send SMS notifications
- Send email notifications
- Secure API with secret key authentication
- Deployed as an AWS Lambda function
- Automated CI/CD with GitHub Actions
This service is deployed as an AWS Lambda function and provides two main endpoints:
/send-sms- For sending SMS messages/send-email- For sending emails
- Node.js 20+
- npm
- AWS CLI
- Doppler CLI (for secrets management)
-
Clone the repository
git clone https://github.com/firstlovecenter/flc-notify-service.git cd flc-notify-service -
Install dependencies
npm ci cd functions/notify npm ci -
Set up environment variables The service uses Doppler for secrets management. You need to set up the following environment variables:
FLC_NOTIFY_KEY- Secret key for API authentication- Additional secrets for SMS and email providers
All API endpoints require the x-secret-key header for authentication.
Endpoint: POST /send-sms
Headers:
Content-Type: application/jsonx-secret-key: YOUR_SECRET_KEY
Request Body:
{
"to": "+1234567890",
"message": "Your message here"
}Response:
200 OK- Message sent successfully403 Forbidden- Invalid or missing secret key502 Bad Gateway- Failed to send message
Endpoint: POST /send-email
Headers:
Content-Type: application/jsonx-secret-key: YOUR_SECRET_KEY
Request Body:
{
"to": "recipient@example.com",
"subject": "Email Subject",
"html": "<p>Email content</p>",
"from": "sender@example.com"
}Response:
200 OK- Email sent successfully403 Forbidden- Invalid or missing secret key502 Bad Gateway- Failed to send email
The service is automatically deployed to AWS Lambda when changes are pushed to the main branch and affect files in the functions/notify directory.
-
Build the project:
cd functions/notify npm run build -
Package the Lambda function:
mkdir -p lambda-package cp -r functions/notify/*.js lambda-package/ mkdir -p lambda-package/lib cp lib/secrets.js lambda-package/lib/ cp functions/notify/.env lambda-package/ cp functions/notify/package.json lambda-package/ cd lambda-package && npm ci --production -
Create the deployment ZIP:
cd lambda-package zip -r ../notify-lambda.zip . -
Deploy to AWS Lambda:
aws lambda update-function-code --function-name flc-notify-service --zip-file fileb://notify-lambda.zip
This project uses GitHub Actions for CI/CD. The workflow:
- Triggers on pushes to the
mainbranch that affect thefunctions/notifydirectory - Installs dependencies
- Builds the TypeScript code
- Packages the Lambda function
- Deploys to AWS Lambda
- Sends a notification to Slack
functions/
notify/
index.ts # Main entry point for the Lambda function
sendEmail.ts # Email sending functionality
sendSMS.ts # SMS sending functionality
utils.ts # Utility functions
lib/
secrets.js # Secrets management
-
Start the service locally:
npm run start -
Test the endpoints:
curl -X POST http://localhost:8888/.netlify/functions/notify/send-sms \ -H "Content-Type: application/json" \ -H "x-secret-key: YOUR_SECRET_KEY" \ -d '{"to": "+1234567890", "message": "Test message"}'
- Create a new branch for your feature
- Make your changes
- Submit a Pull Request to the
mainbranch
ISC License
- John-Dag Addy