EventBridge event bus
EventBridge (opens in a new tab) 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:
serverless.yml
functions:
# ...
resizeImage:
handler: App\MyHandler
runtime: php-83
events:
- eventBridge:
pattern:
detail-type:
- 'MyCustomEvent'
The App\MyHandler
class will be instantiated by Laravel's service container.
You can learn more about messaging with EventBridge in Serverless Visually Explained (opens in a new tab).
Learn more about all the options available for EventBridge in serverless.yml
in the Serverless Framework documentation (opens in a new tab).