Developer Guide: Building a RedwoodJS Scheduling & Reminder System with AWS SNS & EventBridge - code-examples -

Frequently Asked Questions

You can schedule reminders in a RedwoodJS application by leveraging AWS EventBridge Scheduler to trigger events at specific times, which then activate a backend process to send notifications via AWS SNS. This setup ensures reliable, scalable scheduling and notification delivery. The reminder details are stored in a PostgreSQL database managed by Prisma, RedwoodJS's ORM.
AWS EventBridge Scheduler is used to trigger the reminder notifications. It acts as a serverless cron job system, reliably executing tasks at scheduled times. This removes the need for managing a separate scheduling infrastructure, simplifying the application's architecture.
AWS SNS provides a scalable and reliable way to send notifications across multiple channels, including email, SMS, and push notifications. Its decoupled nature ensures that notification delivery doesn't impact the core application logic, improving resilience and maintainability.
Prisma is RedwoodJS's default ORM and is used throughout the application lifecycle to interact with the PostgreSQL database. It simplifies database operations by providing a type-safe and convenient way to create, read, update, and delete reminder records.
Create a new project by running the command `yarn create redwood-app redwood-sns-scheduler --typescript --git-init --commit-message 'Initial project setup'`. The `--typescript` flag initializes a TypeScript project, `--git-init` creates a Git repository, and `--commit-message` sets the initial commit message.
The tutorial uses PostgreSQL as the database. It is managed by Prisma, RedwoodJS's built-in Object-Relational Mapper (ORM), enabling easy interaction between the application and the database.
The RedwoodJS application interacts with AWS SNS to send email notifications. The Lambda function, triggered by EventBridge Scheduler, queries the database for due reminders and publishes JSON-formatted messages to an SNS topic. This topic is subscribed to an email endpoint, ensuring delivery to the specified recipient.
The RedwoodJS scheduler uses AWS SNS for sending notifications, EventBridge Scheduler for triggering events, Lambda for running the notification logic, and potentially Secrets Manager for storing database credentials securely. These services provide a serverless architecture for the application.
The Lambda function needs access to the database credentials and permission to publish to the designated SNS topic. An IAM role specifically for the Lambda function is created with these permissions, ensuring secure access to resources.
The status field in the `Reminder` model tracks the reminder's lifecycle, using values like `PENDING`, `SENT`, and `ERROR`. This allows for efficient management and monitoring of the reminder's delivery status.
Storing `scheduledAt` as UTC in the database ensures consistency and avoids timezone-related issues, especially when dealing with users across different geographical locations. This guarantees the reminder is triggered at the correct time regardless of the user's local timezone.
Environment variables are stored in a `.env` file in the project root. This file contains sensitive information like database credentials, AWS access keys, and SNS topic ARNs. For the Lambda function, environment variables are configured through the AWS Lambda console.
You'll need Node.js (v20.x recommended), Yarn (v1.22.21+), an AWS account with necessary permissions, AWS CLI, RedwoodJS CLI, basic Git knowledge, and optionally Docker for local PostgreSQL.
Although not explicitly implemented in the basic tutorial, multi-user support can be added by associating reminders with users in the database schema. This allows filtering reminders based on the current user and enhances data privacy.