Question about getting data from AWS Batch and CloudWatch

0

Hello, I am trying to create a dashboard on Amazon QuickSight using data from AWS Batch and CloudWatch logs. I have some jobs on AWS Batch and would like to get the data for failed jobs. Each job in AWS Batch has logs on CloudWatch, which can be accessed under log stream name on job specifics. I would like to extract data from the log events on that job on CloudWatch. Is there a way to get that data, so that I can use them on Amazon QuickSight?

1 Answer
0

To extract data from AWS Batch job logs on CloudWatch and use it in Amazon QuickSight, you can follow these steps:

Authorize AWS Batch to access CloudWatch logs:
    In the AWS Batch console, go to the "Job Definitions" section.
    Select the job definition you want to access logs for.
    In the "Log Configuration" section, ensure the "Authorize Batch to use CloudWatch" option is checked.

Retrieve the log data from CloudWatch:
    You can use the AWS CLI or AWS SDK to retrieve the log data from CloudWatch Logs.
    Here's an example using the AWS CLI to get the log events for a specific log stream:

aws logs get-log-events --log-group-name /aws/batch/job --log-stream-name <log-stream-name>

Replace
<log-stream-name>
with the actual log stream name for your AWS Batch job.

Prepare the data for Amazon QuickSight:
    You can export the log data to a file or store it in an Amazon S3 bucket.
    Once the data is in a format that QuickSight can consume (e.g., CSV, Parquet, etc.), you can create a new data source in QuickSight and connect it to the data.

Create a dashboard in Amazon QuickSight:
    In the QuickSight console, create a new analysis or dashboard.
    Add visualizations and widgets to display the data from the AWS Batch job logs.
    You can use QuickSight's built-in features to filter, aggregate, and analyze the data as needed.
AWS
answered 24 days ago
  • Also, if you don't mind, could you please share an example of how to use AWS SDK to get the job logs? Thank you.

  • Is there a way to automate the process of extracting the data? Instead of extracting and importing the data manually, I am trying to find a way so that the dashboard updates automatically whenever there is a new failed jobs created. Also, is there a way to just get the logs for the failed jobs on AWS Batch? I am considering using AWS SDK.

  • You can use SDK method get_log_events(). For an example in python response = cloudwatch_logs.get_log_events( logGroupName='my-log-group', logStreamName='my-log-stream' ) for event in response['events']: print(event['message']) refer below link for more https://docs.aws.amazon.com/code-library/latest/ug/python_3_cloudwatch-logs_code_examples.html

    ** is there a way to just get the logs for the failed jobs on AWS Batch? Without cloudwatch?? :- No, I am not aware

  • Thank you so much for your answer Vinit! Maybe I have explained the question vaguely. I want to get the logs for the failed jobs on AWS Batch through CloudWatch. CloudWatch contains the logs for the failed job on AWS Batch. This is a pseudocode for what I want to achieve: for job in AWS.Batch.exampleJobQueue: if job.status is fail: go to the link under job stream name on job details and export the log from CloudWatch

    I don't know if that pseudocode makes sense. Maybe AWS Lambda might be able to do this? Is there a way to do that?

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