DEV Community

Manish
Manish

Posted on

What is Amazon SNS (Simple Notification Service)?

Amazon SNS (Simple Notification Service) is a fully managed pub/sub messaging service provided by Amazon Web Services (AWS). It enables developers to send messages to multiple recipients, including email, SMS, mobile push notifications, and more.
Before we get started, make sure you have the AWS SDK for JavaScript installed and configured on your machine. You can install it using NPM by running the following command:

npm install aws-sdk
Once you have the SDK installed, you can start using the SNS service in your application. Here’s an example of how to send a push notification to a mobile device using SNS:

const AWS = require('aws-sdk');
const sns = new AWS.SNS();
const params = {
Message: 'Hello from Amazon SNS!',
MessageStructure: 'string',
TargetArn: '<Your target ARN>'
};
sns.publish(params, (err, data) => {
if (err) {
console.error('Error sending SNS message:', err);
} else {
console.log('SNS message sent successfully:', data);
}
});

In this code, we’re creating a new instance of the SNS service using the AWS SDK for JavaScript. We then define the parameters for the message we want to send, including the message content and the target ARN (Amazon Resource Name) of the mobile device we want to send the message to. The publish method is then used to send the message to the target device.

Top comments (0)