Skip to content

PHP Fatal error: Uncaught RuntimeException: SNS message type header not provided. #53

@gioutn19

Description

@gioutn19

Please fill out the sections below to help us address your issue.

Version of AWS SDK for PHP?

"aws/aws-sdk-php": "~2.6.0",

Version of Amazon SNS Message Validator for PHP?

"aws/aws-php-sns-message-validator": "^1.6"

Version of PHP (php -v)?

PHP 7.2.34

What issue did you see?

when executing I get the following message:

PHP Fatal error: Uncaught RuntimeException: SNS message type header not provided. in /var/www/vhosts/studio/vendor/aws/aws-php-sns-message-validator/src/Message.php:40
Stack trace:

0 /var/www/vhosts/studio/index.php(8): Aws \ Sns \ Message :: fromRawPostData ()

1 {main}

thrown in /var/www/vhosts/studio/vendor/aws/aws-php-sns-message-validator/src/Message.php on line 40

Steps to reproduce

If you have a runnable example, please include it as a snippet or link to a repository/gist for larger code examples.

I install sdk through composer, and I send it to call in an index.php file, is:

require 'vendor/autoload.php';

use Aws\Sns\Message;
use Aws\Sns\MessageValidator;
use Aws\Sns\Exception\InvalidSnsMessageException;

// Instantiate the Message and Validator
$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($message['SubscribeURL']);
}

Additional context

Any additional information relevant to the issue. Examples include any framework you may be using (e.g. Laravel, Wordpress) in conjunction with the AWS SDK for PHP, or PHP/environment config settings if the issue is related to memory or performance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    p3This is a minor priority issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions