[{"data":1,"prerenderedAt":86},["ShallowReactive",2],{"snippet-eventbridge-custom-bus-advanced-subscriber":3},{"id":4,"title":5,"contributors":6,"description":8,"extension":9,"gitHub":10,"introBox":13,"languages":19,"meta":22,"resources":23,"services":34,"snippets":36,"stem":83,"tags":84,"type":20,"__hash__":85},"snippets\u002Fsnippets\u002Feventbridge-custom-bus-advanced-subscriber.json","Advanced Custom Event Bus Subscriber Configuration",[7],"content\u002Fcontributors\u002Fmarco-buss.json","Create three EventBridge custom event bus subscribers, each using more features: filter, then retry and dead-letter queue, then a JSONata transform.","json",{"template":11},{"repoURL":12},"https:\u002F\u002Fgithub.com\u002Faws-samples\u002Fserverless-snippets\u002Ftree\u002Fmain\u002Feventbridge-custom-bus-advanced-subscriber",{"headline":14,"text":15},"How it works",[16,17,18],"A subscriber on an Amazon EventBridge custom event bus delivers matching events to a target, and can filter, retry, dead-letter, and transform along the way. This snippet creates three subscribers, each using more of those features than the last, so you can see what each one adds.","Subscriber 1 filters only. Subscriber 2 adds a retry policy and a dead-letter queue for delivery resilience. Subscriber 3 adds a JSONata transform that reshapes the payload before delivery.","The three subscribers use different comparison operators in their filters, and a final block lists more reusable filter values you can swap in. The target, delivery role, and dead-letter queue must belong to the account creating the subscriber.",[20,21],"AWS CLI","YAML",{},{"bullets":24},[25,28,31],{"text":26,"link":27},"Subscribing to events on a custom event bus","https:\u002F\u002Fdocs.aws.amazon.com\u002Feventbridge\u002Flatest\u002Fuserguide\u002Feb-custom-bus-subscribers.html",{"text":29,"link":30},"create-subscriber AWS CLI reference","https:\u002F\u002Fdocs.aws.amazon.com\u002Fcli\u002Flatest\u002Freference\u002Feventsv2\u002Fcreate-subscriber.html",{"text":32,"link":33},"Comparison operators for event patterns","https:\u002F\u002Fdocs.aws.amazon.com\u002Feventbridge\u002Flatest\u002Fuserguide\u002Feb-create-pattern-operators.html",[35],"eventbridge",[37,53,66,79],{"title":38,"codeTabs":39},"Subscriber 1: Filter only",[40,46],{"id":20,"title":20,"description":41,"snippets":42},"Replace the placeholders with your own ARNs. The most basic subscriber: a DATA-scoped filter that delivers only events whose detail.status equals PLACED, and drops everything else.",[43],{"language":44,"code":45},"bash","BUS_ARN=\"&#60;EVENT_BUS_ARN&#62;\"\nQUEUE_ARN=\"&#60;TARGET_QUEUE_ARN&#62;\"\nROLE_ARN=\"&#60;DELIVERY_ROLE_ARN&#62;\"\n\naws eventsv2 create-subscriber \\\n  --name \"orders-basic\" \\\n  --event-bus-arn \"$BUS_ARN\" \\\n  --filter-configuration \"$(cat &#60;&#60;EOF\n{\"Filters\":[{\"Scope\":\"DATA\",\"Pattern\":\"{\\\"detail\\\":{\\\"status\\\":[\\\"PLACED\\\"]}}\"}]}\nEOF\n)\" \\\n  --invoke-configuration \"$(cat &#60;&#60;EOF\n{\"TargetArn\":\"$QUEUE_ARN\",\"RoleArn\":\"$ROLE_ARN\"}\nEOF\n)\"\n",{"id":47,"title":47,"description":48,"snippets":49},"AWS SAM","Deploy with `sam deploy --template-file subscriber1-filter-sam.yaml --stack-name orders-basic-sam --region \u003CEVENT_BUS_REGION> --parameter-overrides EventBusArn=\u003CEVENT_BUS_ARN> TargetArn=\u003CTARGET_QUEUE_ARN> RoleArn=\u003CDELIVERY_ROLE_ARN> --no-confirm-changeset --no-fail-on-empty-changeset`.",[50],{"language":51,"code":52},"css","AWSTemplateFormatVersion: '2010-09-09'\nTransform: AWS::Serverless-2016-10-31\nDescription: Subscriber on an EventBridge enhanced custom event bus with a data filter.\n\nParameters:\n  EventBusArn:\n    Type: String\n    Description: ARN of the enhanced custom event bus to subscribe to.\n  TargetArn:\n    Type: String\n    Description: ARN of the target that receives the events (for example an SQS queue).\n  RoleArn:\n    Type: String\n    Description: ARN of the IAM role EventBridge assumes to invoke the target.\n\nResources:\n  FilteredSubscriber:\n    Type: AWS::EventsV2::Subscriber\n    Properties:\n      Name: !Sub '${AWS::StackName}-orders-basic'\n      EventBusArn: !Ref EventBusArn\n      InvokeConfiguration:\n        TargetArn: !Ref TargetArn\n        RoleArn: !Ref RoleArn\n      FilterConfiguration:\n        Filters:\n          - Scope: DATA\n            Pattern: '{\"detail\":{\"status\":[\"PLACED\"]}}'\n\nOutputs:\n  SubscriberArn:\n    Description: ARN of the created subscriber.\n    Value: !GetAtt FilteredSubscriber.SubscriberArn\n",{"title":54,"codeTabs":55},"Subscriber 2: Filter + retry + dead-letter queue",[56,61],{"id":20,"title":20,"description":57,"snippets":58},"A more resilient subscriber. Adds --retry-policy to retry failed deliveries and --on-failure-configuration to send events that exhaust their retries to an SQS dead-letter queue. Uses a numeric-range filter.",[59],{"language":44,"code":60},"BUS_ARN=\"&#60;EVENT_BUS_ARN&#62;\"\nQUEUE_ARN=\"&#60;TARGET_QUEUE_ARN&#62;\"\nROLE_ARN=\"&#60;DELIVERY_ROLE_ARN&#62;\"\nDLQ_ARN=\"&#60;DEAD_LETTER_QUEUE_ARN&#62;\"\n\naws eventsv2 create-subscriber \\\n  --name \"orders-resilient\" \\\n  --event-bus-arn \"$BUS_ARN\" \\\n  --filter-configuration \"$(cat &#60;&#60;EOF\n{\"Filters\":[{\"Scope\":\"DATA\",\"Pattern\":\"{\\\"detail\\\":{\\\"total\\\":[{\\\"numeric\\\":[\\\"&#62;\\\",100,\\\"&#60;=\\\",500]}]}}\"}]}\nEOF\n)\" \\\n  --invoke-configuration \"$(cat &#60;&#60;EOF\n{\"TargetArn\":\"$QUEUE_ARN\",\"RoleArn\":\"$ROLE_ARN\"}\nEOF\n)\" \\\n  --retry-policy \"$(cat &#60;&#60;EOF\n{\"MaxRetryAttempts\":10,\"MaxEventAgeInSeconds\":3600}\nEOF\n)\" \\\n  --on-failure-configuration \"$(cat &#60;&#60;EOF\n{\"Arn\":\"$DLQ_ARN\"}\nEOF\n)\"\n",{"id":47,"title":47,"description":62,"snippets":63},"Deploy with `sam deploy --template-file subscriber2-filter-retry-dlq-sam.yaml --stack-name orders-resilient-sam --region \u003CEVENT_BUS_REGION> --parameter-overrides EventBusArn=\u003CEVENT_BUS_ARN> TargetArn=\u003CTARGET_QUEUE_ARN> RoleArn=\u003CDELIVERY_ROLE_ARN> DeadLetterQueueArn=\u003CDEAD_LETTER_QUEUE_ARN> --no-confirm-changeset --no-fail-on-empty-changeset`.",[64],{"language":51,"code":65},"AWSTemplateFormatVersion: '2010-09-09'\nTransform: AWS::Serverless-2016-10-31\nDescription: Resilient EventBridge custom event bus subscriber with filter, retry, and DLQ.\n\nParameters:\n  EventBusArn:\n    Type: String\n    Description: ARN of the enhanced custom event bus to subscribe to.\n  TargetArn:\n    Type: String\n    Description: ARN of the target that receives the events (for example an SQS queue).\n  RoleArn:\n    Type: String\n    Description: ARN of the IAM role EventBridge assumes to invoke the target and the DLQ.\n  DeadLetterQueueArn:\n    Type: String\n    Description: ARN of the SQS queue that receives events that exhaust their retries.\n\nResources:\n  ResilientSubscriber:\n    Type: AWS::EventsV2::Subscriber\n    Properties:\n      Name: !Sub '${AWS::StackName}-orders-resilient'\n      EventBusArn: !Ref EventBusArn\n      InvokeConfiguration:\n        TargetArn: !Ref TargetArn\n        RoleArn: !Ref RoleArn\n      FilterConfiguration:\n        Filters:\n          - Scope: DATA\n            Pattern: '{\"detail\":{\"total\":[{\"numeric\":[\"&#62;\",100,\"&#60;=\",500]}]}}'\n      RetryPolicy:\n        MaxRetryAttempts: 10\n        MaxEventAgeInSeconds: 3600\n      OnFailureConfiguration:\n        Arn: !Ref DeadLetterQueueArn\n\nOutputs:\n  SubscriberArn:\n    Description: ARN of the created subscriber.\n    Value: !GetAtt ResilientSubscriber.SubscriberArn\n",{"title":67,"codeTabs":68},"Subscriber 3: Filter + retry + dead-letter queue + JSONata transform",[69,74],{"id":20,"title":20,"description":70,"snippets":71},"The fully featured subscriber. Adds --transformer with Type JSONATA to reshape the payload before delivery, on top of the filter, retry, and dead-letter queue. Uses an $or filter across fields.",[72],{"language":44,"code":73},"BUS_ARN=\"&#60;EVENT_BUS_ARN&#62;\"\nQUEUE_ARN=\"&#60;TARGET_QUEUE_ARN&#62;\"\nROLE_ARN=\"&#60;DELIVERY_ROLE_ARN&#62;\"\nDLQ_ARN=\"&#60;DEAD_LETTER_QUEUE_ARN&#62;\"\n\naws eventsv2 create-subscriber \\\n  --name \"orders-full\" \\\n  --event-bus-arn \"$BUS_ARN\" \\\n  --filter-configuration \"$(cat &#60;&#60;EOF\n{\"Filters\":[{\"Scope\":\"DATA\",\"Pattern\":\"{\\\"detail\\\":{\\\"\\$or\\\":[{\\\"priority\\\":[\\\"HIGH\\\"]},{\\\"total\\\":[{\\\"numeric\\\":[\\\"&#62;=\\\",1000]}]}]}}\"}]}\nEOF\n)\" \\\n  --invoke-configuration \"$(cat &#60;&#60;EOF\n{\"TargetArn\":\"$QUEUE_ARN\",\"RoleArn\":\"$ROLE_ARN\"}\nEOF\n)\" \\\n  --retry-policy \"$(cat &#60;&#60;EOF\n{\"MaxRetryAttempts\":10,\"MaxEventAgeInSeconds\":3600}\nEOF\n)\" \\\n  --on-failure-configuration \"$(cat &#60;&#60;EOF\n{\"Arn\":\"$DLQ_ARN\"}\nEOF\n)\" \\\n  --transformer \"$(cat &#60;&#60;EOF\n{\"Type\":\"JSONATA\",\"JsonataConfiguration\":{\"Expression\":\"{% { \\\"orderId\\\": \\$events.Data.detail.orderId, \\\"total\\\": \\$events.Data.detail.total } %}\"}}\nEOF\n)\"\n",{"id":47,"title":47,"description":75,"snippets":76},"Deploy with `sam deploy --template-file subscriber3-filter-retry-dlq-transform-sam.yaml --stack-name orders-full-sam --region \u003CEVENT_BUS_REGION> --parameter-overrides EventBusArn=\u003CEVENT_BUS_ARN> TargetArn=\u003CTARGET_QUEUE_ARN> RoleArn=\u003CDELIVERY_ROLE_ARN> DeadLetterQueueArn=\u003CDEAD_LETTER_QUEUE_ARN> --no-confirm-changeset --no-fail-on-empty-changeset`.",[77],{"language":51,"code":78},"AWSTemplateFormatVersion: '2010-09-09'\nTransform: AWS::Serverless-2016-10-31\nDescription: Fully featured EventBridge subscriber with filter, retry, DLQ, and JSONata transform.\n\nParameters:\n  EventBusArn:\n    Type: String\n    Description: ARN of the enhanced custom event bus to subscribe to.\n  TargetArn:\n    Type: String\n    Description: ARN of the target that receives the events (for example an SQS queue).\n  RoleArn:\n    Type: String\n    Description: ARN of the IAM role EventBridge assumes to invoke the target and the DLQ.\n  DeadLetterQueueArn:\n    Type: String\n    Description: ARN of the SQS queue that receives events that exhaust their retries.\n\nResources:\n  FullSubscriber:\n    Type: AWS::EventsV2::Subscriber\n    Properties:\n      Name: !Sub '${AWS::StackName}-orders-full'\n      EventBusArn: !Ref EventBusArn\n      InvokeConfiguration:\n        TargetArn: !Ref TargetArn\n        RoleArn: !Ref RoleArn\n      FilterConfiguration:\n        Filters:\n          - Scope: DATA\n            Pattern: '{\"detail\":{\"$or\":[{\"priority\":[\"HIGH\"]},{\"total\":[{\"numeric\":[\"&#62;=\",1000]}]}]}}'\n      RetryPolicy:\n        MaxRetryAttempts: 10\n        MaxEventAgeInSeconds: 3600\n      OnFailureConfiguration:\n        Arn: !Ref DeadLetterQueueArn\n      Transformer:\n        Type: JSONATA\n        JsonataConfiguration:\n          Expression: '{% { \"orderId\": $events.Data.detail.orderId, \"total\": $events.Data.detail.total } %}'\n\nOutputs:\n  SubscriberArn:\n    Description: ARN of the created subscriber.\n    Value: !GetAtt FullSubscriber.SubscriberArn\n",{"title":80,"description":81,"language":44,"code":82},"Filtering with comparison operators","Five DATA-scoped filter values using EventBridge comparison operators: numeric range, anything-but, begins-with (prefix), exists, and $or across fields. Swap any one into the --filter-configuration of a subscriber above.","# Numeric (range): total &#62; 100 and &#60;= 500.\nFILTER='{\"Filters\":[{\"Scope\":\"DATA\",\"Pattern\":\"{\\\"detail\\\":{\\\"total\\\":[{\\\"numeric\\\":[\\\"&#62;\\\",100,\\\"&#60;=\\\",500]}]}}\"}]}'\n\n# Anything-but: status is any value except \"CANCELLED\".\nFILTER='{\"Filters\":[{\"Scope\":\"DATA\",\"Pattern\":\"{\\\"detail\\\":{\\\"status\\\":[{\\\"anything-but\\\":\\\"CANCELLED\\\"}]}}\"}]}'\n\n# Begins with (prefix): region starts with \"us-\".\nFILTER='{\"Filters\":[{\"Scope\":\"DATA\",\"Pattern\":\"{\\\"detail\\\":{\\\"region\\\":[{\\\"prefix\\\":\\\"us-\\\"}]}}\"}]}'\n\n# Exists: the couponCode field is present.\nFILTER='{\"Filters\":[{\"Scope\":\"DATA\",\"Pattern\":\"{\\\"detail\\\":{\\\"couponCode\\\":[{\\\"exists\\\":true}]}}\"}]}'\n\n# Or across fields ($or): priority is \"HIGH\" OR total is &#62;= 1000.\nFILTER='{\"Filters\":[{\"Scope\":\"DATA\",\"Pattern\":\"{\\\"detail\\\":{\\\"$or\\\":[{\\\"priority\\\":[\\\"HIGH\\\"]},{\\\"total\\\":[{\\\"numeric\\\":[\\\"&#62;=\\\",1000]}]}]}}\"}]}'\n","snippets\u002Feventbridge-custom-bus-advanced-subscriber",[],"85OV0bC2aYVBGSaa6zCHpoztsDjUYGyz7hVoTtU2jxs",1794047670308]