AWS Batch get all failed job name on specific Job Queue?

0

Is there a way to use AWS SDK or some python script to get all the job names that failed on specific job queue on AWS Batch? After extracting them, I would like to upload this to AWS S3 or RDS so that I can use it for Amazon QuickSight.

1 Answer
1
Accepted Answer

Hi John,

You can use this python script as reference and modify according to your need.

import boto3

Create Batch and S3 clients

batch_client = boto3.client('batch') s3_client = boto3.client('s3')

Specify the job queue name

job_queue_name = 'your-job-queue-name'

Retrieve the list of failed job names

failed_job_names = [] response = batch_client.list_jobs(jobQueue=job_queue_name, jobStatus='FAILED') while 'nextToken' in response: failed_job_names.extend([job['jobName'] for job in response['jobSummaryList']]) response = batch_client.list_jobs(jobQueue=job_queue_name, jobStatus='FAILED', nextToken=response['nextToken']) failed_job_names.extend([job['jobName'] for job in response['jobSummaryList']])

Write the list of failed job names to a file

with open('failed_job_names.txt', 'w') as f: f.write('\n'.join(failed_job_names))

Upload the file to an Amazon S3 bucket

s3_client.upload_file('failed_job_names.txt', 'your-s3-bucket-name', 'failed_job_names.txt')

AWS
answered a month ago
profile picture
EXPERT
reviewed a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions