getlift / lift

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

Queue Subscriptions #344

Open cmcnicholas opened 1 year ago

cmcnicholas commented 1 year ago

This PR adds support for subscriptions in Queue constructs, see: #266

There are quite a few use cases for this but a common pattern is "fanout" https://aws.amazon.com/getting-started/hands-on/send-fanout-event-notifications/ used to distribute messages to multiple queues that have different processing concerns/domains.

Example using this functionality.

service: lift-test
configValidationMode: error

plugins:
  - serverless-lift

provider:
  name: aws
  region: eu-west-1
  versionFunctions: false

resources:
  Resources:
    MyTopic:
      Type: 'AWS::SNS::Topic'
      Properties:
        TopicName: SuperTopic

constructs:
  ## adds a simple queue and unfiltered subscription against an ARN
  my-queue:
    type: queue
    worker:
      handler: worker.handler
    subscriptions:
      - topicArn: arn:aws:sns:eu-west-1:XXXXXXXXX:AnotherTopic

  ## more complex: adds multiple filtered subscriptions against an ARN and resource defined in this config
  my-queue:
    type: queue
    worker:
      handler: worker.handler
    subscriptions:
      - topicArn: arn:aws:sns:eu-west-1:XXXXXXXXX:DifferentTopic
      - topicArn: arn:aws:sns:eu-west-1:XXXXXXXXX:AlternateTopic
        filters:
          - attribute: yyy
            allows:
              - hello
              - world
      - topicRef: MyTopic
        filters:
          - attribute: xxx
            denied:
              - other
              - world
cmcnicholas commented 12 months ago

This PR is now ready :)