in src/scripts/nf-aws.py [0:0]
def log(args):
session = boto3.Session(region_name=args.region, profile_name=args.profile)
batch = session.client('batch')
cwlogs = session.client('logs')
response = batch.describe_jobs(jobs=[args.jobid])
jobs = response['jobs']
for job in jobs:
if args.step:
step(session, job, args.step)
else:
try:
log_stream_name = job['container']['logStreamName']
response = cwlogs.get_log_events(logGroupName="/aws/batch/job", logStreamName=log_stream_name)
events = response['events']
for event in events:
ts = datetime.utcfromtimestamp(event['timestamp']/1000).strftime('%Y-%m-%d %H:%M:%S')
print(f"[{ts}] {event['message']}")
except (KeyError, cwlogs.exceptions.ResourceNotFoundException):
print("No log found. Either the job has not started yet or there was an error.")