Need help with AWS cloudwatch log insight query

0

I am storing a message in a log stream of aws. For a particular time interval these are the 2 logs on which I need to write a query which I will run on log insight.

logs on which the query will run

I want to write a query which will return the differnce of time stamps(in minutes) between (finished at field from pipeline_2) & (started at field from pipeline_1)

Note: time stamps are in this format (2023-04-14T19:10:47.494-05:00), in order to make the logs compact I removed micro seconds and the timezone

I have tried to calculate both these values individually by running 2 different scripts but unable to achieve that, I see a very limited options with aws log insight and also I am not an expert at it, please help

1 Answer
0

You could write a python or other script in Lambda or off platform to query the cloud watch logs and then do the calculation between the two timestaps.

def lambda_handler(event, context):
    client = boto3.client('logs')

    # Specify your log groups
    log_group1 = '/aws/lambda/your_lambda_function1'
    log_group2 = '/aws/lambda/your_lambda_function2'

....... other code


response1 = client.start_query(
        logGroupName=log_group1,
        startTime=start_timestamp,
        endTime=end_timestamp,
        queryString='fields @timestamp, @message | sort @timestamp desc',
    )

.... query other log....

calculate difference in time stamps
profile picture
JFoxUK
answered 10 months ago
  • Thankyou for the suggestion, sure I will try that. I guess doing it from the query will be easier, if you have a way to do it from query itself please let me know

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions