I am unable to get the confirmation of AWS SNS Http connection in PHP. My application is developed on Laravel 5.1
In AWS I have created a Topic and added a subscription. I have selected endpoint as HTTP and provided the URL http://myurl.com/sns.
My PHP code is below
public function getSnsMessage()
{
$message = Message::fromRawPostData();
$validator = new MessageValidator();
// Validate the message and log errors if invalid.
try {
$validator->validate($message);
}catch (InvalidSnsMessageException $e) {
// Pretend we're not here if the message is invalid.
http_response_code(404);
error_log('SNS Message Validation Error: ' . $e->getMessage());
die();
}
// Check the type of the message and handle the subscription.
if ($message['Type'] === 'SubscriptionConfirmation') {
// Confirm the subscription by sending a GET request to the SubscribeURL
file_get_contents(public_path() . '/awssns.txt','SUB URL MESSAGE = '.$message['SubscribeURL'].PHP_EOL, FILE_APPEND );
}
}
My route file entry is:
Route::get('/sns', [
'as' => 'sns',
'uses' => 'SnsEndpointController@getSnsMessage',
]);
In the browser when I call the URL – http://myurl.com/sns, I get the below error.
RuntimeException in Message.php line 35:SNS message type header not provided.
1. in Message.php line 35
2. at Message::fromRawPostData() in SnsEndpointController.php line 26
3. at SnsEndpointController->getSnsMessage(object(Request))
4. at call_user_func_array(array(object(SnsEndpointController),
'getSnsMessage'), array(object(Request))) in Controller.php line 256
I have the following in my composer:
"aws/aws-sdk-php-laravel": "^3.1",
"aws/aws-php-sns-message-validator": "^1.2"
Any help on how to resolve this error and to get confirmation of my subscription?