getlift / lift

Expanding Serverless Framework beyond functions using the AWS CDK
MIT License
912 stars 111 forks source link

Add EventBridge source to queues #284

Open adamjq opened 1 year ago

adamjq commented 1 year ago

Start from the Use-case

First of all, thanks for this project 🙌 it's a great concept. This a feature request to enhance the Queue construct that might benefit others.

Adding an SQS queue and DLQ between AWS EventBridge and AWS Lambda can be useful for:

  1. Improved storage and ability to retry if failures occur
  2. Protecting a microservice from large bursts of traffic by throttling the delivery of messages

See EventBridge to SQS: Building fault-tolerant microservices

As a producer, I'd like to publish events to AWS EventBridge and not have to add messages to a queue directly.

This pattern has already been implemented in AWS SAM, and as a custom CDK construct.

Example Config

The Serverless Framework already provides an EventBridge connection for functions, and I could see this feature using the same approach https://www.serverless.com/framework/docs/providers/aws/events/event-bridge

For example:

constructs:
  my-queue:
    type: queue
    events:
      - eventBridge:
          pattern:
            detail-type:
              - payments.InvoicePaid

Implementation Idea

The existing CDK construct could be used as a starting point for inspiration https://github.com/awslabs/aws-solutions-constructs/tree/main/source/patterns/%40aws-solutions-constructs/aws-eventbridge-sqs