Skip to Content
πŸŽ‰ Bref 3.0 is released. Read more β†’

SNS events

To handle SNS events, extend the SnsHandler class:

use Bref\Context\Context; use Bref\Event\Sns\SnsEvent; use Bref\Event\Sns\SnsHandler; class MyHandler extends SnsHandler { public function handleSns(SnsEvent $event, Context $context): void { foreach ($event->getRecords() as $record) { $message = $record->getMessage(); // do something } } }

Then, create a Lambda function that listens to SNS events with the handler you created:

serverless.yml
functions: # ... worker: handler: App\MyHandler runtime: php-84 events: - sns: my-topic

The App\MyHandler class will be instantiated by Laravel’s service container.

The sns event creates the SNS topic on deployment. Learn more about using SNS in serverless.yml in the Serverless Framework documentationΒ , for example to subscribe to an existing topic.

Error handling

If the handler throws an exception, Lambda retries the event twice, then drops it. Read Error handling to keep failed events.

Last updated on