npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

sns-to-slack-webhook

v0.1.2

Published

AWS CDK construct that forwards Amazon SNS messages to Slack via Incoming Webhooks.

Readme

sns-to-slack-webhook

AWS CDK construct that forwards Amazon SNS messages to Slack via Incoming Webhooks.

Turn any SNS topic into Slack alerts. The construct wires up a Lambda to your topic and posts structured messages to Slack (Block Kit).


Features

  • Drop‑in CDK v2 construct – bring your own sns.ITopic.
  • Ready‑to‑deploy Lambda (Node.js 22.x) bundled automatically by NodejsFunction.
  • Secrets Manager integration – Slack webhook parts are read securely at runtime.
  • Minimal config – sensible defaults for description and log retention.

Installation

npm i sns-to-slack
# peer deps (most CDK projects already have these):
npm i aws-cdk-lib constructs

This library declares aws-cdk-lib and constructs as peerDependencies.


Quick start

import { Stack } from 'aws-cdk-lib';
import * as sns from 'aws-cdk-lib/aws-sns';
import { SnsToSlack } from 'sns-to-slack-webhook';

export class ExampleStack extends Stack {
  constructor(scope: Construct, id: string) {
    super(scope, id);

    const topic = new sns.Topic(this, 'ExampleTopic', {
      displayName: 'example-topic',
      topicName: 'example-topic',
    });

    new SnsToSlack(this, 'SnsToSlack', {
      snsTopic: topic,
      // optional overrides
      // secretName: 'slack/webhook',
      // description: 'SNS to Slack Webhook',
      // logRetentionDays: 30,
    });
  }
}

Publish any JSON message to the topic — the Lambda will format it and deliver to Slack.


Slack & secret setup

The Lambda expects the Slack Incoming Webhook to be provided via AWS Secrets Manager.

  • Secret name: defaults to slack/webhook (override with the secretName prop).
  • Secret value (JSON) must contain the three parts of a Slack webhook URL:
{
  "Workspace": "T12345678",
  "Channel": "B23456789",
  "Webhook": "xYzABC123..."
}

These map to a full Slack URL of the form:

https://hooks.slack.com/services/<Workspace>/<Channel>/<Webhook>

Create the secret (example):

aws secretsmanager create-secret \
  --name slack/webhook \
  --secret-string '{"Workspace":"T12345678","Channel":"B23456789","Webhook":"xYzABC123"}'

You need a Slack app with Incoming Webhooks enabled. Paste the generated webhook URL and split its path segments into the fields above.


$1

Required & optional

  • Required

    • snsTopic (sns.ITopic): SNS topic to subscribe the Lambda to.
  • Optional

    • secretName (string, default: "slack/webhook"): Name of the AWS Secrets Manager secret with Slack webhook parts (Workspace, Channel, Webhook).
    • description (string, default: "SNS to Slack Webhook"): Description assigned to the Lambda function.
    • logRetentionDays (number, default: 30): CloudWatch Logs retention in days.

Props summary

| Prop | Type | Required | Default | Description | | ------------------ | ------------ | -------- | ----------------- | ------------------------------------------------- | | snsTopic | sns.ITopic | Yes | — | Topic the Lambda subscribes to. | | secretName | string | No | "slack/webhook" | Secrets Manager name holding Slack webhook parts. | | description | string | No | "SNS to Slack Webhook" | Lambda description. | | logRetentionDays | number | No | 30 | CloudWatch Logs retention days. |

Runtime defaults (created resources)

  • Lambda runtime: Node.js 22.x
  • Architecture: ARM64
  • Timeout: 10 seconds
  • Bundling: minify: true, sourceMap: true
  • Environment: SECRET_NAME=<your secret name>, NODE_ENV=production
  • Subscription: Lambda is subscribed to the topic with protocol LAMBDA

What the construct creates

  • A Lambda function (Node.js 22.x, ARM64) with source bundled from this package’s lambda/ folder.

  • Subscription of the Lambda to the provided SNS topic.

  • Permissions:

    • secretsmanager:GetSecretValue for the configured secret.
    • Allow SNS to invoke the Lambda.
  • Environment: SECRET_NAME=<your secret name>; optional logging retention.


Message format in Slack

Messages are posted using Slack Block Kit (simple summary layout). You can fork and customize lambda/utils.ts if you need richer formatting.


Troubleshooting

TS2322: Type 'Topic' is not assignable to type 'ITopic' Make sure you pass an sns.ITopic (e.g., new sns.Topic(...) satisfies that) and that your project has a single installation of aws-cdk-lib (this library lists CDK as a peerDependency).

ValidationError: Cannot find entry file at ./lambda/index.ts Use the published package from npm. The construct resolves its Lambda entry internally; you shouldn’t need to set entry yourself.


Development (optional)

  • This package is written in TypeScript and targets CDK v2.
  • Build: npm run build
  • Lint: npm run lint
  • The Lambda code lives under lambda/ and is bundled by NodejsFunction.

License

MIT See LICENSE for details.


Links