简体   繁体   English

SMS 的 Amazon AWS SNS 传输状态具有随机日志流

[英]Amazon AWS SNS Delivery Status For SMS has random Log Streams

I am using Amazon's php sdk.我正在使用亚马逊的 php sdk。

I use Amazon SNS service to send direct sms.我使用 Amazon SNS 服务直接发送短信。 When I send an sms from my php application it gives me a message ID.当我从我的 php 应用程序发送短信时,它会给我一个消息 ID。

I have to track the delivery status of each of my message.我必须跟踪每条消息的发送状态。 I have enabled cloud watch logs for Text Messaging using Manage text messaging preferences settings.我使用Manage text messaging preferences设置为Text Messaging启用了云监视日志。 The IAM role is properly configured and logs end in Cloudwatch. IAM 角色已正确配置并且日志在 Cloudwatch 中结束。

Now the problem I am facing is that the system creates a random log stream for every message i send.现在我面临的问题是系统为我发送的每条消息创建一个随机日志流。

Here is a screen shot.这是一个屏幕截图。

在此处输入图像描述

I have sent six messages and all of them has been successful( I am sending them to myself).我已经发送了六条消息,并且都成功了(我正在发送给自己)。 And against every message a single log stream exists.针对每条消息,存在一个日志流。

API gives me a function to get logs based upon LogGroupName and LogGroupStream. API 给了我一个函数来获取基于 LogGroupName 和 LogGroupStream 的日志。 The LogGroupName remains the same but LogGroupStream is differnt for every message. LogGroupName 保持不变,但每条消息的 LogGroupStream 都不同。

here is the sdk call这是 sdk 调用

$result = $client->getLogEvents([
    'endTime' => <integer>,
    'limit' => <integer>,
    'logGroupName' => '<string>', // REQUIRED
    'logStreamName' => '<string>', // REQUIRED
    'nextToken' => '<string>',
    'startFromHead' => true || false,
    'startTime' => <integer>,
]);

How should i get the Logs?我应该如何获取日志? Is there a way to tell amazon to log all of sms deliveries to a single LOG STREAM.有没有办法告诉亚马逊将所有短信发送记录到单个日志流中。 So i know the stream and can query for logs.所以我知道流并且可以查询日志。

With a Query:通过查询:

$result = $CloudWatchclient->startQuery([
    'endTime' => strtotime("+5 minutes", strtotime($creation_date)) * 1000, 
    'limit' => 1,
    'logGroupName' => '.....DirectPublishToPhoneNumber',
    'queryString' => 'field @message like /'.$awsmessageid.'/',
    'startTime' => strtotime($creation_date)*1000,
]);

$queryid = $result->get('queryId');
sleep(2);

$result = $CloudWatchclient->getQueryResults([
    'queryId' => $queryid, // REQUIRED
]);
$result = $result->get('results');

The result containt the event log with sms data success结果包含带有短信数据成功的事件日志

You could use filterLogEventsMethod from CloudWatchLogsClient:您可以使用 CloudWatchLogsClient 中的 filterLogEventsMethod:

$result = $client->filterLogEvents(array(    
'logGroupName' => 'string', //Required
'startTime' => integer,
'endTime' => integer,
'filterPattern' => 'string',
'nextToken' => 'string',
'limit' => integer,
'interleaved' => true || false));

Reference: Aws Docs参考资料: AWS 文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM