This documentation is not maintained. Please refer to doc.castsoftware.com/technologies to find the latest updates.

Support for AWS SNS:

Supported APIs

The following APIs are supported:

For SDK V2

AWS.SNS({apiVersion: '2010-03-31'}).publish(params)
NodeJS AWS SNS Publisher object is created. Its name is that of the topic.
AWS.SNS({apiVersion: '2010-03-31'}).subscribe(params)
NodeJS AWS SNS Subscriber object is created. Its name is that of the topic. Then for each supported protocol, an object is created with a callLink from the subscriber to that object.

For SDK V3

new SNSClient({region: REGION}).send(new PublishCommand(params));
NodeJS AWS SNS Publisher object is created. Its name is that of the topic.
new SNSClient({region: REGION}).send(new SubscribeCommand(params));
NodeJS AWS SNS Subscriber object is created. Its name is that of the topic. Then for each supported protocol, an object is created with a callLink from the subscriber to that object. 

Supported protocols

The com.castsoftware.wbslinker will create a callLink between the SNS Publishers and SNS Subscribers which have the same name.

ProtocolObject createdObject name
emailNodeJS Emailan Email (the email addresses are not evaluated).
smsNodeJS SMSan SMS (the SMS numbers are not evaluated).
http/httpsNodeJS AWS Post HttpRequers servicethe URL (evaluated from the endpoint).
sqsNodeJS AWS Simple Queue Service Publisherthe name of the queue (evaluated from the endpoint).
lambdaNodeJS Call to AWS Lambda Functionthe name of the Lambda function (evaluated from the endpoint).

Examples

API v2

When analyzing the following source code:

var AWS = require('aws-sdk');
// Set region
AWS.config.update({region: 'REGION'});
// Create promise and SNS service object

var sns = new AWS.SNS({apiVersion: '2010-03-31'})

function my_subscribe(params) {
    sns.subscribe(params, function (err, data) {
        if (err) console.log(err, err.stack); // an error occurred
        else console.log(data);           // successful response
    });
}

function my_publish(params) {
    sns.publish(params);
}

function foo() {
    let topicArn = "arn:aws:sns:eu-west-3:757025016730:testTopic";
    my_subscribe({Protocol: "EMAIL", TopicArn: topicArn, Endpoint: "EMAIL_ADDRESS"})
    my_subscribe({Protocol: "SMS", TopicArn: topicArn, Endpoint: "911"})
    my_subscribe({Protocol: "LAMBDA", TopicArn: topicArn, Endpoint: "arn:aws:lambda:eu-west-3:757025016730:testLambda"})
    my_subscribe({Protocol: "HTTP", TopicArn: topicArn, Endpoint: "http:/myapi.api.test.com"})
 }
function bar() {
    const params2 = {
        TopicArn: "arn:aws:sns:eu-west-3:757025016730:testTopic",
        Message: "MESSAGE_TEXT"
    };
    my_publish(params2)
}

The following results will be produced:

API v3

When analyzing the following source code:

const {SNSClient} = require("@aws-sdk/client-sns");
// Set the AWS Region.
const REGION = "us-east-1";
// Create SNS service object.
const snsClient = new SNSClient({region: REGION});
export {snsClient};

// ====== Import required AWS SDK clients and commands for Node.js
const {PublishCommand} = require("@aws-sdk/client-sns");
const {SubscribeCommand} = require("@aws-sdk/client-sns");

const subscription = async () => {
    try {
        let topicArn = "arn:aws:sns:eu-west-3:757025016730:testTopic";
        const data1 = await snsClient.send(new SubscribeCommand({Protocol: "EMAIL", TopicArn: topicArn, Endpoint: "test@mail.com"}));
        const data2 = await snsClient.send(new SubscribeCommand({Protocol: "SMS", TopicArn: topicArn, Endpoint: "911"}));
        const data3 = await snsClient.send(new SubscribeCommand({Protocol: "LAMBDA", TopicArn: topicArn, Endpoint: "arn:aws:lambda:eu-west-3:757025016730:testLambda"}));
        const data4 = await snsClient.send(new SubscribeCommand({Protocol: "HTTP", TopicArn: topicArn, Endpoint: "http:/myapi.api.test.com"}));
        console.log("Success.", data1);
        return data1;
    } catch (err) {
        console.log("Error", err.stack);
    }
};
subscription();

const run = async () => {
    // Set the parameters
    const params = {
        Message: "MESSAGE_TEXT", // MESSAGE_TEXT
        TopicArn: "arn:aws:sns:eu-west-3:757025016730:testTopic", //TOPIC_ARN
    };
    try {
        const data = await snsClient.send(new PublishCommand(params));
        console.log("Success.", data);
        return data; // For unit tests.
    } catch (err) {
        console.log("Error", err.stack);
    }
};
run();

The following results will be produced: