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
Parameter | Type | Description |
---|---|---|
snsClient | SNSClient | The SNSClient from AWS SDK. |
topicArn | string | The ARN of the topic to publish to. |
logger? | Logger | The PowerTools logger instance to enable logging. |
Returns
SnsPublisher
Methods
publish()
ts
publish(message, topicArn): Promise<PublishCommandOutput>;
Publishes a single message via SNS.
Parameters
Parameter | Type | Description |
---|---|---|
message | string | The raw message payload. |
topicArn | string | The 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
Parameter | Type | Description |
---|---|---|
message | unknown | The message which will be published as JSON. |
Returns
Promise
<PublishCommandOutput
>
publishRaw()
ts
publishRaw(message): Promise<PublishCommandOutput>;
Publishes a raw message via SNS.
Parameters
Parameter | Type | Description |
---|---|---|
message | string | The raw message payload. |
Returns
Promise
<PublishCommandOutput
>