1

I am new in Aws, I am using Aws SNS to send notification, i am sending notifications to different topic not to endpoint. This is working perfectly.

When i publish notification, i got array like

object(Aws\Result)#84 (1) {
    ["data":"Aws\Result":private]=>
       array(2) {
         ["MessageId"]=>
         string(36) "************-7a29-591f-8765-************"
         ["@metadata"]=>
         array(4) {
         ["statusCode"]=>
         int(200)
         ["effectiveUri"]=>
        string(40) "https://sns.ap-southeast-1.amazonaws.com"
        ["headers"]=>
        array(4) {
            ["x-amzn-requestid"]=>
            string(36) "************-b737-5831-abf4-************"
            ["content-type"]=>
            string(8) "text/xml"
            ["content-length"]=>
            string(3) "294"
            ["date"]=>
            string(29) "Fri, 28 Oct 2016 08:59:05 GMT"
        }
        ["transferStats"]=>
            array(1) {
               ["http"]=>
               array(1) {
               [0]=>
               array(0) {}
            }
        }
    }
}

I am using php at server side, How can i get notification delivery status of all recepients by this message id?

Thanks in Anticipants.

4

2 回答 2

4

您正在询问如何获取通过 Amazon SNS 发送的消息的通知传递状态

Using Amazon SNS Topic Attributes for Message Delivery Status文档说:

Amazon SNS 支持记录发送到具有以下 Amazon SNS 终端节点的主题的通知消息的传递状态:

  • 应用
  • HTTP
  • 拉姆达
  • SQS

配置消息传递状态属性后,日志条目将发送到 CloudWatch Logs,以获取发送到订阅 Amazon SNS 终端节点的主题的消息。

我找不到请求状态的特定 API 调用message_id。相反,日志信息似乎被发送到CloudWatch Logs。您需要解析日志以发现状态。

于 2016-10-30T07:55:10.813 回答
0
  1. 对 AWS Cloudwatch 启用“交付状态日志记录”更多信息
  2. 调整用户(在脚本中使用)以访问 AWS Cloudwatch 日志
  3. 使用 awssdk for php 从 cloudwatch 读取日志条目

请参阅下面的示例代码

require 'inc/awsSdkForPhp/aws-autoloader.php';
$params = array(
    'credentials' => array(
        'key' => '<YOUR KEY>',
        'secret' => '<YOUR SECRET>',
    ),
    'region' => 'us-east-1', //  your aws from SNS region
    'version' => 'latest'
);
$cwClient = new \Aws\CloudWatchLogs\CloudWatchLogsClient($params);
$queryRes = $cwClient->startQuery([
  'endTime' => 1621231180,  // UNIX TIMESTAMP 
  'logGroupName' => 'sns/us-east-1/***/DirectPublishToPhoneNumber', // YOUR LOG GROUP NAME
  'queryString' => 'fields @timestamp, status, @message
  | filter notification.messageId="5a419afc-c4b3-55b3-85f9-c3e7676b2dd2"', // YOUR MESSAGE ID
  'startTime' => 1620954551 // START UNIX TIMESTAMP 
]);

$qryID = $queryRes->get('queryId');
sleep(3); // To wait the execution to be completed.
$resultObj =  $cwClient->getQueryResults(array(
  'queryId' => $qryID, // REQUIRED
));

//echo "<pre>";print_r($resultObj);echo "</pre>";
$result = $resultObj->get('results');

$jsnRs = json_decode($result[0][2]['value']); // TO get the delivery array 

echo "<br>status :".$jsnRs->status;
echo "<br>phone Carrier :".$jsnRs->delivery->phoneCarrier;
echo "<br>provider Response :".$jsnRs->delivery->providerResponse;
echo "<pre>";print_r($jsnRs);echo "</pre>";

我相信它会帮助某人

于 2021-05-21T11:25:30.280 回答