1

I need to retrieve a specific log from aws cloudwatch logs and send it out through email.

I have tried adding below filter pattern in Trigger but this is filtering events from past that is 2 months back. It is not considering the starttime & endtime provided.

Below is the filter patterns:

response = log_client.filter_log_events(
logGroupName='/path/path/path',
filterPattern='jobId',
#limit=1,
#startTime=start_epoch,
#endTime=end_epoch
)

sample Json format which i need to retrieve from cloudwatch logs and send to email is :

{
"jobId": "123456",
"success": "OK",
"message": "Scheduled"
}
Kranthi Sama
  • 498
  • 3
  • 10
  • 28
  • 1
    I am not sure this will help entirely but I think you might want to query your logs and get the required data and then send it in the email notification. Here is how querying is done using boto3 client: https://stackoverflow.com/questions/59240107/how-to-query-cloudwatch-logs-using-boto3-in-python – Anup Nov 20 '20 at 11:39
  • I didn't understand why using a Lambda trigger with filter pattern didn't work for you. Can you please elaborate on that? – Sarthak Jain Nov 20 '20 at 18:29
  • @SarthakJain Lambda trigger with filter pattern only invokes the lambda when particular filter pattern observed in cloudwatch, but i wanted to retrieve that particular value from cloudwatch like json value. – Kranthi Sama Nov 23 '20 at 16:32

2 Answers2

0

You can use https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/SubscriptionFilters.html, And trigger a lambda. We use that in Lumigo to help monitor your env and read the logs

0

I am able to achieve it using below.

response = log_client.filter_log_events(
    logGroupName='/path/path/path',
    filterPattern='jobId',
    startTime=start_epoch,
    endTime=end_epoch
)
Kranthi Sama
  • 498
  • 3
  • 10
  • 28