Frequently Asked Questions
This involves using Node.js, Express for building a RESTful API, AWS SNS for message delivery, and AWS EventBridge Scheduler to trigger messages at specific times. The API interacts with a database (like PostgreSQL) to store schedule information and with AWS services to manage the scheduling and publishing of messages.
EventBridge Scheduler is a serverless scheduling service that allows you to precisely schedule one-time or recurring tasks. In this system, it's used to trigger messages to be sent to an AWS SNS topic at the user-defined times, replacing the need for complex cron jobs or maintaining scheduler instances.
Node.js and Express are chosen for their popularity, ease of use in building RESTful APIs, and ability to handle asynchronous operations efficiently. Express simplifies routing and request handling, making it ideal for the API layer of this system.
Use cron expressions for recurring reminders, such as daily or weekly notifications, by specifying the cron syntax in the 'cronExpression' field. Use 'scheduledTime' for one-time reminders, providing an ISO 8601 timestamp for the specific future time the message should be sent.
The system uses AWS Simple Notification Service (SNS) to manage message publishing and subscriptions, and AWS EventBridge Scheduler to trigger notifications at scheduled times. You'll also need an IAM user for programmatic access, an IAM role for the Scheduler and a Database (Postgres, MySQL, SQLite etc.) to store message details.
The example uses PostgreSQL and Prisma ORM, where Prisma defines the database schema (schema.prisma) and manages database interactions. You'll need to define a 'Schedule' model in your schema.prisma file and migrate it to your database instance using Prisma CLI commands.
When creating a schedule via the API, provide a cron expression in the cronExpression field. For a weekday schedule, a cron expression like cron(0 10 ? MON-FRI ) would trigger every weekday at 10:00 AM UTC. Refer to the AWS documentation for detailed cron syntax.
Yes, while the guide uses PostgreSQL with Prisma, you can adapt the concepts and use Prisma with MySQL, SQLite, SQL Server, or MongoDB by changing the provider and DATABASE_URL accordingly in schema.prisma.
This system leverages AWS SNS topics, which support multiple subscribers. After setting up the reminder system, subscribe different endpoints (email, SMS, Lambda functions, etc.) to the SNS topic to receive the messages when they're published.
Send a DELETE request to the API endpoint /api/schedules/{id}, replacing {id} with the schedule's ID. This triggers logic to remove both the scheduled task from AWS EventBridge and the schedule details from the database.
You need Node.js and npm/yarn, an AWS account, AWS CLI (optional), basic understanding of JavaScript, Node.js, Express, and REST APIs, a text editor, Docker (for containerization), and a PostgreSQL database (or another supported database).
Docker allows you to package the application and its dependencies into a container, which ensures consistent execution across different environments. This simplifies deployment to various platforms (like AWS ECS, EKS, or App Runner) as the container includes everything needed to run the app.
You can implement more specific error catching within the controller and service layers to provide more informative error messages to users. A global error handler in the Express app can ensure consistent responses for errors, and using a structured logging library like Winston provides more comprehensive error logging for debugging.
While the base implementation doesn't explicitly retry, you can configure EventBridge Scheduler's retry policy in the RetryPolicy section of awsService.js. Set MaximumEventAgeInSeconds and MaximumRetryAttempts to control how long EventBridge retries before giving up. Additionally, you can configure a Dead Letter Queue to capture and analyze failed invocations.
Content Loading Error
We encountered an error while processing this content.