Skip to content

Instantly share code, notes, and snippets.

@faneder
Created September 11, 2018 03:21
Show Gist options
  • Save faneder/2b640066e1dbac374205b53ce16f9b3e to your computer and use it in GitHub Desktop.
Save faneder/2b640066e1dbac374205b53ce16f9b3e to your computer and use it in GitHub Desktop.
handle notification from AWS SNS
<?php
use Notification;
use Aws\Sns\Message;
use Aws\Sns\MessageValidator;
use Aws\Sns\Exception\InvalidSnsMessageException;
class SNSController extends Controller
{
public function handleNotification()
{
$message = Message::fromRawPostData();
$validator = new MessageValidator();
// Validate the message
try {
$validator->validate($message);
} catch (InvalidSnsMessageException $e) {
Log::error('SNS Message Validation Error: ' . $e->getMessage());
}
// find which notification is failing, you can notify the sender to change the correct email address
$notification = Notification::where('ses_message_id', $message['Message']['mail']['messageId'])->first();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment