[Python] How to query cloudwatch logs using boto3 in python

Discussão em 'Python' iniciado por Stack, Julho 12, 2025.

  1. Stack

    Stack Membro Participativo

    I have a lambda function that writes metrics to Cloudwatch. While, it writes metrics, It generates some logs in a log-group.

    INFO:: username: simran+test@example.com ClinicID: 7667 nodename: MacBook-Pro-2.local

    INFO:: username: simran+test2@example.com ClinicID: 7667 nodename: MacBook-Pro-2.local

    INFO:: username: simran+test@example.com ClinicID: 7668 nodename: MacBook-Pro-2.local

    INFO:: username: simran+test3@example.com ClinicID: 7667 nodename: MacBook-Pro-2.local


    I would like to query AWS logs in past x hours where x could be anywhere between 12 to 24 hours, based on any of the params.

    For ex:

    1. Query Cloudwatch logs in last 5 hours where ClinicID=7667

    or

    1. Query Cloudwatch logs in last 5 hours where ClinicID=7667 and username='simran+test@example.com'

    or

    1. Query Cloudwatch logs in last 5 hours where username='simran+test@example.com'

    I am using boto3 in Python.

    Continue reading...

Compartilhe esta Página