Frequently Asked Questions
You can send SMS messages using RedwoodJS by integrating with AWS SNS. Build a RedwoodJS app, configure AWS credentials, define your data models with Prisma, and implement a GraphQL API endpoint to trigger the sending process via the AWS SDK for JavaScript. This allows you to manage subscribers and send targeted campaigns directly from your application.
RedwoodJS is the core framework for building this full-stack, serverless-friendly application. It provides the structure for the frontend (React), backend (GraphQL API with Prisma ORM), and simplifies deployment to AWS Lambda and S3/CloudFront. Its integrated nature streamlines development and deployment processes.
AWS SNS is a managed messaging service chosen for its reliability, scalability, and direct SMS integration capabilities. It handles the complexities of sending messages at scale, allowing your RedwoodJS application to focus on campaign and subscriber management.
AWS credentials should be configured in the `.env` file at the project root during the initial setup. This file is used during development and is never committed to version control due to security concerns. For production, use `.env.production` which is created after the first deployment.
Yes, you can use SQLite, MySQL, or PostgreSQL as your database. Define your preferred provider in the `api/db/schema.prisma` file and update the `DATABASE_URL` in your `.env` file accordingly. Prisma, Redwood's ORM, supports multiple database providers.
Use the `yarn rw deploy serverless` command. Note: This approach with the serverless framework is deprecated. For the first deployment, the `--first-run` flag is required to set up API and Web sides and to correctly store the `API_URL` in the .env.production file.
Prisma is an ORM (Object-Relational Mapper) that simplifies database interactions. It's used to define data models (Campaign and Subscriber), manage database migrations, and generate the client used within the RedwoodJS services to query and modify the database.
The RedwoodJS documentation mentions that Serverless Framework deployment is deprecated in RedwoodJS v5+. While functional as of November 2023, monitor RedwoodJS announcements for updated deployment strategies to ensure compatibility.
Use Redwood's generators to scaffold CRUD operations (`yarn rw g sdl Campaign --crud`). Implement a `sendCampaign` mutation within `api/src/graphql/campaigns.sdl.ts` and its logic in `api/src/services/campaigns/campaigns.ts` using the AWS SDK for SNS. Return a `SendCampaignResult` type for detailed feedback.
The provided implementation sends messages individually in a loop for granular control and error handling. For large lists, consider SNS topics or batch sending for efficiency, although this may come with additional setup on the SNS side.
The recommended format for phone numbers when using SNS is the international E.164 format. This includes a plus sign followed by the country code and subscriber number, without any other characters like spaces or hyphens. For example, +15551234567.
Add the `DATABASE_URL` environment variable pointing to your production database in the `.env.production` file. This file is created after the first deployment. Do not commit this file to git because it contains sensitive information.
Never hardcode AWS credentials. Store them in .env during development and .env.production for deployment, and do not commit these files to version control. Use IAM roles for Lambda functions for enhanced security and least privilege principles, granting only necessary permissions like 'sns:Publish'.
Use `try...catch` blocks around API operations, log informative messages with Redwood's `logger`, return meaningful error messages through GraphQL without revealing sensitive data, and monitor CloudWatch for production issues.
Logs from your deployed RedwoodJS application, including Lambda function execution logs and SNS delivery status logs, can be found in AWS CloudWatch. Redwood's logger integrates with CloudWatch, providing structured logs for easier debugging.
Content Loading Error
We encountered an error while processing this content.