Skip to content

API reference / @backpack/amazon-sns / SnsPublisher

Class: SnsPublisher

Utility for publishing messages to Amazon SNS.

Example

ts
import { SNSClient } from "@aws-sdk/client-sns";
import { SnsPublisher } from "@backpack/amazon-sns";

const client = new SNSClient();
const publisher = new SnsPublisher(client, "my-topic-arn");

// publishes the message as raw payload
await publisher.publishRaw("raw payload");

// publishes the message as JSON payload
await publisher.publishJson({ foo: 'Foo' });

Constructors

Constructor

ts
new SnsPublisher(
   snsClient, 
   topicArn, 
   logger?): SnsPublisher;

Parameters

ParameterTypeDescription
snsClientSNSClientThe SNSClient from AWS SDK.
topicArnstringThe ARN of the topic to publish to.
logger?LoggerThe PowerTools logger instance to enable logging.

Returns

SnsPublisher

Methods

publish()

ts
publish(message, topicArn): Promise<PublishCommandOutput>;

Publishes a single message via SNS.

Parameters

ParameterTypeDescription
messagestringThe raw message payload.
topicArnstringThe ARN of the topic to publish to.

Returns

Promise<PublishCommandOutput>

Deprecated

Please use SnsPublisher#publishRaw or SnsPublisher#publishJson instead.


publishJson()

ts
publishJson(message): Promise<PublishCommandOutput>;

Publishes a message as JSON via SNS.

Parameters

ParameterTypeDescription
messageunknownThe message which will be published as JSON.

Returns

Promise<PublishCommandOutput>


publishRaw()

ts
publishRaw(message): Promise<PublishCommandOutput>;

Publishes a raw message via SNS.

Parameters

ParameterTypeDescription
messagestringThe raw message payload.

Returns

Promise<PublishCommandOutput>