Sunday, July 20, 2025

How to Publish messages to Amazon SNS.

To twtech publishes messages to Amazon SNS (Simple Notification Service), twtech can use several methods including:

·       The AWS Management Console,

·       AWS CLI,

·        Programming SDK(softeware development kit) like Python (Boto3), Node.js, & many more.

Here’s twtech quick guide for each method:

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:

o   Subject (optional)

o   Message body

o   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:123456789xxx:twtech-Topic" \
  --message "Hello twtech team from AWS CLI!"

To send to a phone number (SMS):

 # bash
aws sns publish \
  --phone-number "+1555123xxxx" \
  --message "This is an SMS message!"

 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:123456789xxx:twtech-Topic',
    Message='Hello twtech team from Boto3!',
    Subject='Test Notification'
) 
print("Message ID:", response['MessageId'])

To send to an SMS number instead:

# python
response = sns.publish(
    PhoneNumber='+15551234567',
    Message='This is an SMS message!'
)

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 twtech team from Node.js!',
  TopicArn: 'arn:aws:sns:us-east-2:123456789xxx:twtech-Topic'
}; 
sns.publish(params, function(err, data) {
  if (err) console.error(err, err.stack);
  else     console.log('Message ID:', data.MessageId);
Steps to Directly Publish (for 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

Kubernetes Clusters | Upstream Vs Downstream.

  The terms "upstream" and "downstream" in the context of Kubernetes clusters often refer to the direction of code fl...