Developer Guide: Sending MMS with Vite, Node.js, and AWS Pinpoint/S3 - code-examples -

Frequently Asked Questions

Use a Node.js backend with the AWS SDK to interact with Pinpoint and S3. The frontend uploads the image to S3 via a presigned URL and the backend triggers the MMS sending via Pinpoint, ensuring secure credential management.
AWS S3 stores the media files (images) included in the MMS message. The Node.js backend generates presigned URLs, allowing the frontend to upload files directly to S3 without exposing AWS credentials.
Presigned URLs allow direct browser uploads to S3 without exposing your AWS secret keys on the client-side. The backend generates these temporary URLs with specific permissions and expiry times, enhancing security.
Configure CORS for your S3 bucket when you're making requests from a different domain (like your frontend app's domain) to your S3 bucket. This is crucial for direct uploads from the browser using presigned URLs.
Standard short codes or 10DLC numbers may require additional registration or may not be universally MMS-capable. Toll-free numbers are generally recommended for MMS and are easier to configure for this purpose. Always verify the capabilities of your number in the Pinpoint console.
On your Node.js backend, use the `@aws-sdk/s3-request-presigner` library. Create a `PutObjectCommand` for the desired S3 object, then call `getSignedUrl` with the S3 client, the command, and expiry options.
Pinpoint SMS and Voice v2 is used to send SMS and MMS messages, including media attachments like images. It provides a reliable and scalable way to deliver messages from your application.
Create a new IAM user with programmatic access and attach a policy allowing S3 `PutObject`, `PutObjectAcl` (if necessary), and `pinpoint-sms-voice:SendMediaMessage` actions, specifying the S3 bucket ARN and region in the IAM policy resource definition.
Use the same AWS region for your S3 bucket, IAM user, and Pinpoint phone number. Consistency across these services is crucial for the proper functioning of the application.
Ensure you have correctly configured CORS on your S3 bucket. The allowed origins in the CORS configuration must include your frontend app's origin (domain, port, protocol).
Use npm: `npm install @aws-sdk/client-s3 @aws-sdk/s3-request-presigner @aws-sdk/client-pinpoint-sms-voice-v2` installs the required packages to interact with S3 and Pinpoint.
The backend project includes `server.js` (main application), `.env` (environment variables), `package.json`, `node_modules`, and `.gitignore`. The `.env` file stores sensitive AWS credentials and configuration.
Implement `try...catch` blocks around AWS SDK calls in the backend. On the frontend, use `try...catch` and consider `axios.isAxiosError` to distinguish backend errors from S3 issues. Provide informative status updates on the frontend UI.
Use the E.164 format for phone numbers when sending MMS messages with AWS Pinpoint, e.g., +12065550100. Ensure proper formatting both in the frontend input and in the backend validation.