A TypeScript-based notification handler built with AWS SAM that processes email and SMS notifications using AWS Lambda, Amazon SES, and Amazon SNS.
This project demonstrates a notification system using AWS SAM and TypeScript. The system processes two types of notifications:
1. Email Notifications: Sent using Amazon Simple Email Service (SES). 2. SMS Notifications: Sent using Amazon Simple Notification Service (SNS).
source/
βββ package.json # Dependencies and scripts
βββ template.yaml # SAM template for AWS resources
βββ tsconfig.json # TypeScript configuration
βββ handler.ts # Lambda entry point
βββ notification/
β βββ email.ts # Email notification logic
β βββ sms.ts # SMS notification logic
β βββ processor.ts # Notification processing logic
β βββ types/ # TypeScript interfaces and types
β β βββ index.ts
β βββ utils/ # Utility functions
β βββ index.ts
βββ tests/ # Unit tests
β βββ ... # Test files
βββ dist/ # Compiled output
βββ .aws-sam/ # SAM build artifacts
βββ events/ # Sample event payloads
βββ node_modules/ # Dependencies- Node.js (version 18 or higher)
- AWS CLI installed and configured with your credentials
- AWS SAM CLI installed
- Docker installed and running (required for local testing with SAM)
- TypeScript installed globally
- Amazon SES setup:
- A verified email in Amazon SES (sandbox or production mode).
- Amazon SNS setup:
- Ensure permissions to publish messages to an SNS topic.
- AWS CLI Configuration:
- Ensure that your AWS CLI is configured with the necessary permissions.
aws configure
- Ensure that your AWS CLI is configured with the necessary permissions.
- Email Configuration:
- Update
senderEmailinnotification/email.tswith your verified SES email.
- Update
- SNS Permissions:
- Ensure that the Lambda role allows
SNS:Publishto your desired topic.
- Ensure that the Lambda role allows
1. Clone the repository
git clone https://github.com/mvelezg99/notification-aws-handler.git
cd source2. Install dependencies
npm install3. Build the project π¨
npm run build4. Build the SAM application π»
npm run sam:build5. Start the local SAM application π
npm run sam:start6. Test the lambda function π€ Use a tool like Postman or cURL to test the Lambda function locally.
- Endpoint:
http://127.0.0.1:3000/notifications - Method:
POST - Body Example:
// For Email
{
"type": "email",
"id": "1",
"timestamp": "2024-12-01T12:00:00Z",
"recipient": "recipient@example.com",
"subject": "Hello",
"body": "This is a test email."
}// For SMS
{
"type": "sms",
"id": "2",
"timestamp": "2024-12-01T12:00:00Z",
"phoneNumber": "+1234567890",
"message": "This is a test SMS."
}Run the unit tests using the following command:
npm run test