Skip to content

Instantly share code, notes, and snippets.

@sjehutch
Created November 3, 2017 13:50
Show Gist options
  • Save sjehutch/190664664cfdad0594b92212086a9d7e to your computer and use it in GitHub Desktop.
Save sjehutch/190664664cfdad0594b92212086a9d7e to your computer and use it in GitHub Desktop.
Webhook in lambda api gateway for sns
<?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