Created
November 3, 2017 13:50
-
-
Save sjehutch/190664664cfdad0594b92212086a9d7e to your computer and use it in GitHub Desktop.
Webhook in lambda api gateway for sns
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require 'path/to/vendor/autoload.php'; | |
use AwsSnsMessageValidatorMessage; | |
use AwsSnsMessageValidatorMessageValidator; | |
use GuzzleHttpClient; | |
if ($_SERVER['REQUEST_METHOD'] !== 'POST') { | |
http_response_code(405); | |
die; | |
} | |
try { | |
$message = Message::fromRawPostData(); | |
$validator = new MessageValidator(); | |
$validator->validate($message); | |
} catch (Exception $e) { | |
http_response_code(404); | |
die; | |
} | |
if ($message->get('Type') === 'SubscriptionConfirmation') { | |
(new Client)->get($message->get('SubscribeURL'))->send(); | |
} elseif ($message->get('Type') === 'Notification') { | |
//Save this to your DB if you want too | |
save_message_to_database($message); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment