I am attempting to read Log data using .NET from CloudWatch for Messages sent using SNS.
From the CloudWatch console (CloudWatch \ CloudWatch Logs \ Logs Insights) I enter:
Date range: custom (2w)
LogGroup: sns/ap...../8...../LogName
Query: fields @timestamp, @message | sort @timestamp desc | limit 20
It returns lots of log records (@timestamp | @message)
I'm trying to do the same from c# using the .net AWS SDK:
public async Task GetLogs()
{
string logGroupName = "sns/ap...../8...../LogName";
AWSOptions options = configuration.GetAWSOptions();
IAmazonCloudWatchLogs logs = options.CreateServiceClient<IAmazonCloudWatchLogs>();
StartQueryRequest startQueryRequest = new StartQueryRequest();
startQueryRequest.LogGroupName = logGroupName;
startQueryRequest.StartTime = 1577850562; //1 Jan 2020
TimeSpan t = DateTime.UtcNow - new DateTime(1970, 1, 1); //Epoch time starts on 1/1/1970
int secondsSinceEpoch = (int)t.TotalSeconds;
startQueryRequest.EndTime = secondsSinceEpoch;
startQueryRequest.QueryString = "fields @timestamp, @message | sort @timestamp desc";
startQueryRequest.Limit = 1000;
StartQueryResponse response2 = await logs.StartQueryAsync(startQueryRequest);
Console.WriteLine();
}
Can't work out why it doesn't return any records.
Response2 =
ContentLength: 50
QueryId: "guid..."
ResponseMetadata:
Metadata Count = 0
RequestId = "guid..."
Any idea what I'm doing wrong? Thanks!