bragg-sns is a specialized middleware designed for the `bragg` micro-framework, facilitating the processing of AWS SNS (Simple Notification Service) events as if they were conventional HTTP requests. This package abstracts the underlying SNS message structure, allowing developers to define routes for specific SNS topics using a `sns:TopicName` prefix within `bragg-router`. The core message content is then made available through `ctx.request.body`. The current stable version is 2.0.0, which notably enhanced functionality by adding support for SNS message attributes. The package integrates tightly with `bragg` and `bragg-router`, making it a suitable choice for building event-driven, serverless applications, particularly in AWS Lambda environments. It also provides topic name mapping capabilities, allowing for flexible event routing and consolidation via object or function-based transformations.
npm install bragg-snsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates setting up `bragg` with `bragg-sns` and `bragg-router` to handle SNS events, including a simple topic mapping and local simulation for testing.
Ensure all SNS event routes are prefixed, e.g., `router.post('sns:YourTopicName', ...)`.Review how `ctx.request.body` is consumed in your handlers to ensure it correctly parses messages that may now include attribute data or have a slightly altered structure due to attribute handling in v2.0.0.
For ESM projects, consider using a CommonJS wrapper, configuring your build system to handle CJS modules, or sticking to `require()` within a CJS-compatible file.
Change the route definition from `router.post('MyTopic', ...)` to `router.post('sns:MyTopic', ...)`.Ensure `app` and `router` are initialized with parentheses: `const app = require('bragg')();` and `const router = require('bragg-router')();`.If possible, rename your file to `.cjs` or configure your `package.json` with `"type": "commonjs"`. Alternatively, use dynamic `import()` for CJS modules within ESM, or consider a bundling step.