Skip to content

Latest commit

 

History

History
438 lines (284 loc) · 14.2 KB

API.md

File metadata and controls

438 lines (284 loc) · 14.2 KB

cdk-eventbridge-to-sqs

This is a CDK construct library that allows you to easily create an EventBridge rule that sends events to an SQS queue.

Why not use AWS Solutions constructs aws-eventbridge-sqs?

Because it doesn't support message group id.

So, that's why.

Documentation

API Reference

Usage

Install

npm install cdk-eventbridge-to-sqs

Import

import { EventbridgeToSqs } from "cdk-eventbridge-to-sqs";

Examples

Create an eventbus and a queue, and connect them

const { queue, eventBus } = new EventbridgeToSqs(this, "EventbridgeToSqs");

Create an eventbus and a queue with custom names, and connect them

const { queue, eventBus } = new EventbridgeToSqs(this, "EventbridgeToSqs", {
  eventBusProps: {
    eventBusName: "MyEventBus",
  },
  queueProps: {
    queueName: "MyQueue",
  },
});

Create an eventbus, a queue and a dead letter queue with custom names, and connect them

const { queue, eventBus } = new EventbridgeToSqs(this, "EventbridgeToSqs", {
  eventBusProps: {
    eventBusName: "MyEventBus",
  },
  queueProps: {
    fifo: true,
  },
  deadLetterQueueProps: {
    fifo: true,
  },
  deployDeadLetterQueue: true,
  messageGroupId: "MyMessageGroupId",
});

Connect an existing eventbus and queue

declare const queue: Queue;
declare const eventBus: EventBus;

new EventbridgeToSqs(this, "EventbridgeToSqs", {
  existingEventBusInterface: eventBus,
  existingQueueObj: queue,
});

Custom event rule filter pattern

declare const queue: Queue;
declare const eventBus: EventBus;

new EventbridgeToSqs(this, "EventbridgeToSqs", {
  existingEventBusInterface: eventBus,
  existingQueueObj: queue,
  eventRuleFilterPattern: {
    detailType: ["MyDetailType"],
    source: ["MySource"],
  },
});

API Reference

Constructs

EventbridgeToSqs

Initializers

import { EventbridgeToSqs } from 'cdk-eventbridge-to-sqs'

new EventbridgeToSqs(scope: Construct, id: string, props?: EventbridgeToSqsProps)
Name Type Description
scope constructs.Construct No description.
id string No description.
props EventbridgeToSqsProps No description.

scopeRequired
  • Type: constructs.Construct

idRequired
  • Type: string

propsOptional

Methods

Name Description
toString Returns a string representation of this construct.

toString
public toString(): string

Returns a string representation of this construct.

Static Functions

Name Description
isConstruct Checks if x is a construct.

isConstruct
import { EventbridgeToSqs } from 'cdk-eventbridge-to-sqs'

EventbridgeToSqs.isConstruct(x: any)

Checks if x is a construct.

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

xRequired
  • Type: any

Any object.


Properties

Name Type Description
node constructs.Node The tree node.
eventBus aws-cdk-lib.aws_events.IEventBus No description.
queue aws-cdk-lib.aws_sqs.Queue No description.
rule aws-cdk-lib.aws_events.Rule No description.
deadLetterQueue aws-cdk-lib.aws_sqs.DeadLetterQueue No description.

nodeRequired
public readonly node: Node;
  • Type: constructs.Node

The tree node.


eventBusRequired
public readonly eventBus: IEventBus;
  • Type: aws-cdk-lib.aws_events.IEventBus

queueRequired
public readonly queue: Queue;
  • Type: aws-cdk-lib.aws_sqs.Queue

ruleRequired
public readonly rule: Rule;
  • Type: aws-cdk-lib.aws_events.Rule

deadLetterQueueOptional
public readonly deadLetterQueue: DeadLetterQueue;
  • Type: aws-cdk-lib.aws_sqs.DeadLetterQueue

Structs

EventbridgeToSqsProps

The properties for the EventbridgeToSqs class.

Initializer

import { EventbridgeToSqsProps } from 'cdk-eventbridge-to-sqs'

const eventbridgeToSqsProps: EventbridgeToSqsProps = { ... }

Properties

Name Type Description
deadLetterQueueProps aws-cdk-lib.aws_sqs.QueueProps Properties for the dead letter queue, if deployDeadLetterQueue is true.
deployDeadLetterQueue boolean Whether to deploy a dead letter queue for the main queue.
enableQueuePurging boolean Whether to enable queue purging.
eventBusProps aws-cdk-lib.aws_events.EventBusProps Properties for the new event bus that will be created.
eventRuleFilterPattern aws-cdk-lib.aws_events.EventPattern Event pattern to use for the event rule Defaults to an event pattern that matches all events in the same region as the event bus.
eventRuleProps aws-cdk-lib.aws_events.RuleProps Properties for the new event rule that will be created.
existingEventBusInterface aws-cdk-lib.aws_events.EventBus An existing event bus to bind the rule to.
existingQueueObj aws-cdk-lib.aws_sqs.Queue Existing queue object to bind the event source to.
maxReceiveCount number Max receive count for the dead letter queue.
messageGroupId string The message group id to use for fifo queues.
queueProps aws-cdk-lib.aws_sqs.QueueProps Properties for the new queue that will be created, if no existing queue is provided.

deadLetterQueuePropsOptional
public readonly deadLetterQueueProps: QueueProps;
  • Type: aws-cdk-lib.aws_sqs.QueueProps
  • Default: None

Properties for the dead letter queue, if deployDeadLetterQueue is true.


deployDeadLetterQueueOptional
public readonly deployDeadLetterQueue: boolean;
  • Type: boolean
  • Default: false

Whether to deploy a dead letter queue for the main queue.


enableQueuePurgingOptional
public readonly enableQueuePurging: boolean;
  • Type: boolean
  • Default: false

Whether to enable queue purging.

If true, the queue will be purged before deployment


eventBusPropsOptional
public readonly eventBusProps: EventBusProps;
  • Type: aws-cdk-lib.aws_events.EventBusProps
  • Default: None

Properties for the new event bus that will be created.


eventRuleFilterPatternOptional
public readonly eventRuleFilterPattern: EventPattern;
  • Type: aws-cdk-lib.aws_events.EventPattern
  • Default: None

Event pattern to use for the event rule Defaults to an event pattern that matches all events in the same region as the event bus.


eventRulePropsOptional
public readonly eventRuleProps: RuleProps;
  • Type: aws-cdk-lib.aws_events.RuleProps
  • Default: None

Properties for the new event rule that will be created.


existingEventBusInterfaceOptional
public readonly existingEventBusInterface: EventBus;
  • Type: aws-cdk-lib.aws_events.EventBus
  • Default: A new event bus will be created

An existing event bus to bind the rule to.


existingQueueObjOptional
public readonly existingQueueObj: Queue;
  • Type: aws-cdk-lib.aws_sqs.Queue
  • Default: None

Existing queue object to bind the event source to.

If not provided, a new queue will be created. If an existing queue is provided, the queue will not be modified unless enableQueuePurging is set to true or deployDeadLetterQueue is set to true


maxReceiveCountOptional
public readonly maxReceiveCount: number;
  • Type: number
  • Default: 3

Max receive count for the dead letter queue.


messageGroupIdOptional
public readonly messageGroupId: string;
  • Type: string

The message group id to use for fifo queues.


queuePropsOptional
public readonly queueProps: QueueProps;
  • Type: aws-cdk-lib.aws_sqs.QueueProps
  • Default: None

Properties for the new queue that will be created, if no existing queue is provided.