-
Notifications
You must be signed in to change notification settings - Fork 1
boto3
HOA PHAN edited this page Jun 23, 2023
·
2 revisions
scroll cwlogs
import boto3
import datetime
LOG_GROUP='/aws/lambda/xxxxx'
SINCE=1600786543938
LIM=10000
FILTER_PATTERN='{$.topic="xxxxxx"}'
PROFILE='xxxx'
session = boto3.Session(profile_name=PROFILE)
client = session.client('logs')
response = client.filter_log_events(logGroupName=LOG_GROUP, startTime=1600786543938, filterPattern=FILTER_PATTERN, limit = LIM)
currentToken = response['nextToken']
while True and currentToken:
events = []
response = client.filter_log_events(limit = LIM, filterPattern=FILTER_PATTERN, startTime=SINCE, logGroupName=LOG_GROUP, nextToken=currentToken)
currentToken = response['nextToken'] if 'nextToken' in response else None
if(len(response['events']) > 0):
events = events.extend(response['events'])
print(len(response['events']))
lastE = response['events'][-1]
print(datetime.datetime.fromtimestamp(lastE['timestamp']/1000).strftime('%Y-%m-%d %H:%M:%S'))
f = open("events.log", "w")
f.writelines(["%s\n" % (e) for e in sorted(events)])
f.close()