@themainstack/sns-events
v1.3.1
Published
Utility to trigger AWS SNS events
Readme
@themainstack/sns-events
A utility package to easily trigger AWS SNS events.
Installation
npm install @themainstack/sns-eventsUsage
Import the triggerEvent function and use it to publish messages to an SNS topic.
import { triggerEvent } from "@themainstack/sns-events";
async function publishSignupEvent() {
const result = await triggerEvent({
region: "us-east-1",
accountId: "123456789012",
eventName: "user_signup_topic", // The name of your SNS topic
payload: {
userId: "user_123",
email: "[email protected]",
timestamp: new Date().toISOString(),
},
});
if (result.status) {
console.log("Success:", result.message);
console.log("Message ID:", result.response.MessageId);
} else {
console.error("Error:", result.message);
console.error("Details:", result.response);
}
}Parameters
The triggerEvent function accepts an options object with the following properties:
region(string): The AWS region where the SNS topic exists (e.g., 'us-east-1').accountId(string): Your 12-digit AWS Account ID.eventName(string): The name of the SNS topic.payload(any, optional): The data you want to send. It will be stringified usingJSON.stringify. Defaults to{}.
Return Value
Returns a Promise that resolves to:
{
status: boolean; // true if success, false otherwise
message: string; // "Event triggered successfully" or error message
response: object; // AWS SNS PublishCommandOutput or error object
}