1

I am using Amazon's php sdk.

I use Amazon SNS service to send direct sms. When I send an sms from my php application it gives me a message 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. The IAM role is properly configured and logs end in 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.

enter image description here

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. The LogGroupName remains the same but LogGroupStream is differnt for every message.

here is the sdk call

$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.

S. A. Malik
  • 3,465
  • 6
  • 37
  • 56
  • 1
    Are you saying you don't know the log stream name that's created as a result of sending a particular message? – Matt S Feb 28 '18 at 14:18
  • @MattS I would say there is not way to know what will be the log stream name, as the log streams are created randomly. Or atleast I think like that. – S. A. Malik Feb 28 '18 at 18:44

2 Answers2

1

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

0

You could use filterLogEventsMethod from CloudWatchLogsClient:

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

Reference: Aws Docs

dtelaroli
  • 1,227
  • 1
  • 13
  • 20