Laravel AWS SNS Events
7.x
7.x
  • โšกIntroduction
  • ๐ŸŽ‰Support
  • Getting Started
    • โฌ†๏ธUpgrading from 6.x
    • ๐Ÿš€Installation
    • ๐Ÿ“กConfiguring Events
    • ๐ŸงชTesting your implementation
  • Customization
    • ๐Ÿ“ฆCustom Payload
    • ๐ŸคฟCustom Event Classes
    • ๐Ÿ”—Custom Method Hooks
  • AWS Webhooks
    • โšกIntroduction
    • ๐Ÿš€Installation
    • ๐Ÿ™ŒShowcase
    • ๐Ÿ–ฅ๏ธSupported AWS Services
      • ๐ŸšจCloudWatch Alerts
      • ๐Ÿ“งSimple Email Service (SES)
      • ๐ŸŒ‰EventBridge Events
    • ๐ŸงชTesting your implementation
Powered by GitBook
On this page

Was this helpful?

  1. AWS Webhooks

Showcase

The package comes with more controllers that will handle each service separately, so you should be implementing different topics for each controller.

You should create a controller that extends one of the package controllers that are displayed below, based on the service you want to get SNS notifications from:

  • \RenokiCo\AwsWebhooks\Http\Controllers\SesWebhook

  • \RenokiCo\AwsWebhooks\Http\Controllers\CloudwatchWebhook

  • \RenokiCo\AwsWebhooks\Http\Controllers\EventbridgeWebhook

A controller that will handle the response for you should be extended & registered in your routes:

use RenokiCo\AwsWebhooks\Http\Controllers\SesWebhook;

class MyAwesomeSesWebhook extends SesWebhook
{
    /**
     * Handle the Bounce event.
     *
     * @param  array  $message
     * @param  array  $originalMessage
     * @param  \Illuminate\Http\Request  $request
     * @return void
     */
    protected function onBounce(array $message, array $originalMessage, Request $request)
    {
        // Unsubscribe the user from newsletter in case of bounce.

        foreach ($message['bounce']['bouncedRecipients'] as $recipient) {
            if ($user = User::whereEmail($recipient['emailAddress'])->first()) {
                $user->update([
                    'subscribed' => false,
                ]);
            }
        }
    }
}
Route::any('/aws-sns-ses', [MyAwesomeSesWebhook::class, 'handle']);

Make sure to whitelist your route in your VerifyCsrfToken.php:

protected $except = [
    // ...
    'aws-sns-ses/',
];

If you have registered the route and created an SNS Topic, you should register the URL and click the confirmation button from the AWS Dashboard. In a short while, if you implemented the route well, you'll be seeing that your endpoint is registered.

PreviousInstallationNextSupported AWS Services

Last updated 3 years ago

Was this helpful?

๐Ÿ™Œ