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

aws-cdk-fanout

v1.0.1

Published

CDK contruct for a Fanout pattern with Api Gateway > SNS > SQS > lambda

Downloads

9

Readme

AWS CDK Fanout Construct

CDK contruct for a Fanout pattern with Api Gateway > SNS > SQS > lambda

npm version License: MIT

Overview

The AWS CDK Fanout construct simplifies creating webhook fanout architectures in AWS. It provides a streamlined way to:

  1. Receive webhook events via API Gateway
  2. Publish events to an SNS topic
  3. Route messages to multiple SQS queues based on filtering criteria
  4. Process messages with Lambda functions

Architecture Diagram

Installation

npm install aws-cdk-fanout

Getting Started

Basic Usage

import { FanoutConstruct, FanoutConstructPropsEntity, SqsToLambdaPropsEntity } from 'aws-cdk-fanout';
import { Duration, Stack } from 'aws-cdk-lib';
import { FilterOrPolicy } from 'aws-cdk-lib/aws-sns';
import { Construct } from 'constructs';

export class MyStack extends Stack {
  constructor(scope: Construct, id: string) {
    super(scope, id);
    
    // Define the SQS to Lambda mapping
    const orderProcessingQueue = new SqsToLambdaPropsEntity({
      lambdaName: 'process-orders',
      handlerPath: 'src/lambdas/process-orders.ts',
      envVars: {
        ENVIRONMENT: 'dev',
      },
      snsFilter: {
        eventType: FilterOrPolicy.stringFilter({
          allowlist: ['order.created', 'order.updated']
        })
      },
      sqsMaxBatchSize: 10,
      sqsMaxBatchingWindow: Duration.seconds(30),
      sqsVisibilityTimeout: Duration.seconds(120)
    });
    
    // Create the fanout construct
    new FanoutConstruct(this, 'WebhooksFanout', new FanoutConstructPropsEntity({
      stage: 'dev',
      region: 'us-east-1',
      sqsToLambda: [orderProcessingQueue]
    }));
  }
}

Lambda Handler Example

Here's an example of a Lambda handler that processes messages from the SQS queue:

import { SQSEvent } from 'aws-lambda';

export const handler = async (event: SQSEvent): Promise<void> => {
  for (const record of event.Records) {
    console.log('Processing message:', record.body);
    
    // Parse the message body
    const message = JSON.parse(record.body);
    const snsMessage = JSON.parse(message.Message);
    
    // Process the message based on your business logic
    console.log('Event data:', snsMessage);
  }
};

Features

  • API Gateway Integration: Automatically creates an API Gateway endpoint to receive webhook events
  • Message Filtering: Filter messages using SNS message filtering attributes
  • Dead Letter Queues: Automatic DLQ setup for failed message processing
  • Batch Processing: Configure batch size and batching window for Lambda processing
  • Secure by Default: Includes API key authentication for the API Gateway endpoint

Advanced Configuration

Multiple Consumers with Different Filters

// Order processing queue
const orderProcessingQueue = new SqsToLambdaPropsEntity({
  lambdaName: 'process-orders',
  handlerPath: 'src/lambdas/process-orders.ts',
  envVars: { /* ... */ },
  snsFilter: {
    eventType: FilterOrPolicy.stringFilter({
      allowlist: ['order.created', 'order.updated']
    })
  },
  sqsMaxBatchSize: 10,
  sqsMaxBatchingWindow: Duration.seconds(30),
  sqsVisibilityTimeout: Duration.seconds(120)
});

// User processing queue
const userProcessingQueue = new SqsToLambdaPropsEntity({
  lambdaName: 'process-users',
  handlerPath: 'src/lambdas/process-users.ts',
  envVars: { /* ... */ },
  snsFilter: {
    eventType: FilterOrPolicy.stringFilter({
      allowlist: ['user.created', 'user.updated']
    })
  },
  sqsMaxBatchSize: 5,
  sqsMaxBatchingWindow: Duration.seconds(60),
  sqsVisibilityTimeout: Duration.seconds(180)
});

// Create the fanout construct with multiple consumers
new FanoutConstruct(this, 'WebhooksFanout', new FanoutConstructPropsEntity({
  stage: 'dev',
  region: 'us-east-1',
  sqsToLambda: [orderProcessingQueue, userProcessingQueue]
}));

Customizing Queue Options

const queue = new SqsToLambdaPropsEntity({
  // ... other properties
  queueOptions: {
    retentionPeriod: Duration.days(7),
    dataKeyReuse: Duration.hours(1),
    encryption: sqs.QueueEncryption.KMS_MANAGED
  }
});

Customizing Lambda Options

const queue = new SqsToLambdaPropsEntity({
  // ... other properties
  lambdaOptions: {
    memorySize: 512,
    timeout: Duration.seconds(30),
    runtime: Runtime.NODEJS_18_X
  }
});

Turning Off Components

new FanoutConstruct(this, 'WebhooksFanout', new FanoutConstructPropsEntity({
  stage: 'dev',
  region: 'us-east-1',
  sqsToLambda: [...],
  removeApiGateway: true,          // Don't create an API Gateway
  removeApiGatewayKeyAuth: true,   // Don't use API key authentication
  removeLambda: true               // Don't create Lambda functions
}));

License

This project is licensed under the MIT License - see the LICENSE file for details.