Search code examples
javaaws-sdkamazon-cloudwatchamazon-cloudwatchlogs

How to access more than 50 LogStreams from AWS WatchCloud with 'DescribeLogStreamsRequest'


I want to access multiple log streams of a log group from cloud watch via java:

AWSLogs logsClient = builder.withCredentials(new AWSStaticCredentialsProvider(awsCreds))
                    .withRegion(Regions.EU_CENTRAL_1)
                    .withClientConfiguration(clientConfig).build();
DescribeLogStreamsRequest describeLogStreamsRequest = new DescribeLogStreamsRequest().withLogGroupName("foo").withOrderBy(OrderBy.LastEventTime).withDescending(true);DescribeLogStreamsResult describeLogStreamsResult = logsClient.describeLogStreams(describeLogStreamsRequest);

 for (LogStream logStream : describeLogStreamsResult.getLogStreams()) {


                GetLogEventsRequest getLogEventsRequest = new GetLogEventsRequest()
                        .withStartTime(startTimestamp)
                        .withEndTime(endTimestamp)
                        .withLogGroupName("fooo")
                        .withLogStreamName(logStream.getLogStreamName());

the documentation states, that 50 log streams is the max. Is there any way to access more than the (latest) 50 log streams?


Solution

  • See comment:

    As you can see in the documentation you provided, there's a nextToken. That's part of every AWS API call that gives a list of elements. You need to create a loop and pass the nextToken so you can get more elements