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 Antwort
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
beantwortet vor einem Jahr
  • 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

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen