Last active
November 13, 2018 18:24
-
-
Save dtelaroli/6126f4c5165d629287623b91f3016517 to your computer and use it in GitHub Desktop.
How to get SMS log from Cloudwatch by message id
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Test { | |
@Test | |
public void shouldGetLogs() { | |
AWSLogs client = AWSLogsAsyncClientBuilder.defaultClient(); | |
//Your date of sent message: ex: 2018-01-01 00:00:00.000 | |
LocalDateTime dateTime = LocalDateTime.of(2018, 1, 1, 0, 0, 0, 0 * 1000); | |
long time = dateTime.toEpochSecond(ZoneOffset.UTC) * 1000; | |
String token = null; | |
List<FilteredLogEvent> list = new ArrayList<>(); | |
do { | |
FilterLogEventsRequest req = new FilterLogEventsRequest() | |
.withLogGroupName("sns/us-east-1/<account_id>/DirectPublishToPhoneNumber") //change account and region | |
.withFilterPattern("{$.notification.messageId = \"<message_id>\"}")) //change message_id | |
.withStartTime(time) | |
.withNextToken(token); | |
FilterLogEventsResult events = client.filterLogEvents(req); | |
list = events.getEvents(); | |
token = events.getNextToken(); | |
System.out.println(token); | |
} while(list.isEmpty() && token != null); //paginate if not found | |
list.stream().forEach(i -> System.out.println(i.getMessage())); | |
assertThat(list.size(), equalTo(1)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment