0

The below code returns records when I run it in debug mode with a breakpoint on this line and stepping into the line. But when I run it in regular Run and do not step into this line, it produces 0 result. What am I doing wrong? Thanks

GetQueryResultsResult getQueryResultsResult = awslogs.getQueryResults(getQueryResultsRequest);
RumanaC
  • 23
  • 5
  • What happens if you put a logging statement immediately after? I wonder if your debug setup is using different AWS credentials, or a different AWS region? You can use **AWS CloudTrail** to see the API calls that are being made to your account to try and diagnose the situation. – John Rotenstein Jun 19 '19 at 02:42

2 Answers2

1

Adding the below line of code, prior to that line of code, has fixed the issue:

TimeUnit.SECONDS.sleep(2);

Thanks

RumanaC
  • 23
  • 5
1

The query is not executed by the method getQueryResults of the CloudWatchLogsClient, is executed when you call startQuery.

The startQuery can take a long to finish its execution, so if you call the getQueryResults immediately after the startQuery, it won't get the results because the query may still be running.

So, to get the results, you can verify if the query is still running by checking the status of the GetQueryResultsResponse like this:

 GetQueryResultsResponse getQueryResultsResponse = null;
 do {
      getQueryResultsResponse = awslogs.getQueryResults(getQueryResultsRequest);
 } while ("Running".equals(getQueryResultsResponse.status().toString()));
Marto
  • 214
  • 2
  • 6