EventBridge event bus
EventBridgeย is a managed event bus that is perfect for exchanging asynchronous messages between applications and microservices.
To handle EventBridge events, extend the EventBridgeHandler class:
use Bref\Context\Context;
use Bref\Event\EventBridge\EventBridgeEvent;
use Bref\Event\EventBridge\EventBridgeHandler;
class MyHandler extends EventBridgeHandler
{
public function handleEventBridge(EventBridgeEvent $event, Context $context): void
{
// We can retrieve the message data via `$event->getDetail()`
$message = $event->getDetail();
// do something
}
}Then, create a Lambda function that listens to EventBridge events with the handler you created:
Laravel
serverless.yml
functions:
# ...
worker:
handler: App\MyHandler
runtime: php-84
events:
- eventBridge:
pattern:
detail-type:
- 'MyCustomEvent'The App\MyHandler class will be instantiated by Laravelโs service container.
Error handling
If the handler throws an exception, Lambda retries the event twice, then drops it. Read Error handling to keep failed events.
You can learn more about messaging with EventBridge in Serverless Visually Explainedย .
Learn more about all the options available for EventBridge in serverless.yml in the Serverless Framework documentationย .
Last updated on
