'AWS CloudWatchLogs do not return logs in Descending order using DescribeLogStreamsRequest
I am using C# AWS SDK to retieve CloudWatch logs in (date-time) descending order (latest-first). So setting up the AmazonCloudWatchLogsClient as follows:
AmazonCloudWatchLogsConfig config = new AmazonCloudWatchLogsConfig {
RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName("<aws-region>")
};
AmazonCloudWatchLogsClient _client = new AmazonCloudWatchLogsClient(config);
_client.DescribeLogStreamsAsync(new DescribeLogStreamsRequest {
LogGroupName = "logGroup",
OrderBy = "LastEventTime",
Descending = true,
});
And setting up cloud watch group and stream as follows:
_client.CreateLogGroupAsync(new CreateLogGroupRequest { LogGroupName = "logGroup" });
_client.CreateLogStreamAsync(new CreateLogStreamRequest {
LogGroupName = "logGroup",
LogStreamName = "logStream"
});
Than retrieving cloud watch logs as follows:
var request = new GetLogEventsRequest
{
LogStreamName = "logStream",
LogGroupName = "logGroup",
StartTime = DateTime.UtcNow.AddDays(-1),
EndTime = DateTime.UtcNow,
Limit = 50,
StartFromHead = false
};
var response = await GetLogEventsAsync(123, 456, 50, "000/f", "000/b");
var logs = response.Events;
The logs are received as always oldest-first, not the latest-first.
Please suggest any fixes.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
