Sunday, July 20, 2025

How to Publish Messages to Amazon SNS | Overview.


How to Publish Messages to Amazon SNS - Overview.

Scope:

  • Intro,
  • Methods to Publish Messages to Amazon SNS,
  • Using AWS Console,
  • Using AWS CLI,
  • Using Python (Boto3),
  • Using Node.js (AWS SDK),
  • Insights.

 Methods to Publish Messages to Amazon SNS

  •        The AWS Management Console (UI)
  •        AWS CLI,
  •         Programming SDK(softeware development kit) like Python (Boto3), Node.js, & many more.

1. Using AWS Console

1.     Go to the Amazon SNS Console

2.     Click "Topics", then select or create a topic.

3.     Choose "Publish message".

4.     Fill out:

    •    Subject (optional)
    •    Message body
    •    Choose message format (JSON, raw text, etc.)

5.     Click "Publish message"

2. Using AWS CLI

  • First, make sure twtech CLI is configured with AWS credentials:

# bash
aws configure

  • Then publish a message like this:

# bash
aws sns publish \
  --topic-arn "arn:aws:sns:us-east-2:accoundID:twtechSNS-Topic" \
  --message "Hello From twtech SNS Team via AWS CLI"

  • To send to a phone number (SMS):

 # bash
aws sns publish \
  --phone-number "+1555123xxxx" \
  --message "This is an SMS message From twtech SNS Team via CLI"

 3. Using Python (Boto3)

# Install Boto3:

# bash
pip install boto3

# Then use this code:

# python
import boto3
# Create an SNS client
sns = boto3.client('sns')
# Publish a message to a topic
response = sns.publish(
    TopicArn='arn:aws:sns:us-east-2:accountID:twtechSNS-Topic',
    Message='Hello from twtech SNS Team via Boto3 CLI',
    Subject='Test Notification'
) 
print("Message ID:", response['MessageId'])

To send to an SMS number instead:

# python
response = sns.publish(
    PhoneNumber='+155512xxxx',
    Message='This is an SMS message from twtech SNS Team via python CLI'
)

4. Using Node.js (AWS SDK)

# bash
npm install aws-sdk
# js
const AWS = require('aws-sdk');
AWS.config.update({ region: 'us-east-2' });
const sns = new AWS.SNS();
const params = {
  Message: 'Hello from twtech SNS Team via Node.js CLI',
  TopicArn: 'arn:aws:sns:us-east-2:accoundID:twtechSNS-Topic'
}; 
sns.publish(params, function(err, data) {
  if (err) console.error(err, err.stack);
  else     console.log('Message ID:', data.MessageId);
Insights
Steps to Directly Publish a message to mobile apps SDK:

  • twtech starts by creating a platform for the application,
  • Next, it creates a platform for the endpoint,
  • Then, it publishes message to the platform endpoint.
  • This works seamlessly for applications like: Google GCM, Apple APNS, Amazon  Device Messaging(ADM).



No comments:

Post a Comment

Amazon EventBridge | Overview.

Amazon EventBridge - Overview. Scope: Intro, Core Concepts, Key Benefits, Link to official documentation, Insights. Intro: Amazon EventBridg...