This project demonstrates how to send one-time passcodes (OTPs) via SMS using Amazon Simple Notification Service (SNS). It includes a Node.js script that generates a random 6-digit OTP and sends it to a specified phone number.
Before running the script, ensure you have the following:
- Node.js installed on your machine.
- An AWS account with appropriate permissions to use the Simple Notification Service (SNS).
- AWS credentials (access key and secret key) stored as environment variables or in an AWS configuration file.
- A
.envfile containing necessary configuration, including phone number and AWS region.
-
Clone this repository to your local machine:
git clone https://github.com/adanzweig/nodejs-aws-sns.git cd nodejs-aws-sns -
Install dependencies:
npm install
-
Create a
.envfile in the project root and add the following:REGION=us-east-1 # Replace with your desired AWS region AWS_ACCESS_KEY=your-access-key AWS_SECRET_KEY=your-secret-key
Run the script to send an OTP via SMS:
npm startThe script will generate a random 6-digit OTP and send it to the specified phone number.
Adjust the parameters in the .env file to customize the SMS message, recipient phone number, and AWS region.
This project is licensed under the MIT License - see the LICENSE file for details.