Programmatically, using boto3 (Python),
log_client=boto3.client('logs')
result_1=log_client.describe_log_streams(logGroupName='<NAME>')
(I don't know what log group names for EC2 instances look like; for Lambda they are of the form '/aws/lambda/FuncName'
. Try grabbing the names you see in the console).
result_1
contains two useful keys: logStreams
(the result you want) and nextToken
(for pagination, I'll let you look up the usage).
Now result_1['logStreams']
is a list of objects containing a logStreamName
. Also useful are firstEventTimestamp
and lastEventTimestamp
.
Now that you have log stream names, you can use
log_client.get_log_events(logGroupName='<name>',logStreamName='<name>'
The response contains nextForwardToken
and nextBackwardToken
for pagination, and events
for the log events you want. Each event contains a timestamp
and a message
.
I'll leave it to you to look up the API to see what other parameters might be useful to you. By the way, the console will let you stream your logs to an S3 bucket or to AWS's ElasticSearch service. ElasticSearch is a joy to use, and Kibana's UI is intuitive enough that you can get results even without learning their query language.