Integrating an AWS Batch Job with Maven

Kavindra Lunuwilage
3 min readSep 29, 2021

--

Prerequisites -

There are a few prerequisites to complete before this integration.

  • The first thing is to have access to an AWS account.
  • After that, navigate to the AWS Management Console and then navigate to the AWS Batch section.
  • Now create a Job Queue related to your project requirement.
  • Once it is done, create a Job Definition that will specify how jobs are to be run.

Integrating with Maven -

For this integration, AWS SDK for Java 2.x is used because it is the latest SDK version, and many breaking changes have been added compared to the AWS SDK for Java 1.x version.

Step 1 —

Add AWS SDK Version 2.x to the project pom.xml file. To do that, copy and paste the following dependencies to the project pom.xml file and reload maven dependencies or use mvn clean install command to get these dependencies to install in your maven project.

Step 2 -

Now create a new class file in the project src folder with any name. For this, I am using AwsBatchClient.java.

Step 3 -

It’s time to implement the AWS Integration. To do that, first, create a method with any name. So here, I have used runAwsBatchJob as the method name. Copy and paste the following code inside the method.

Essential Tips to customize the above code snippet -

  1. The Region should be specified as Region.YOUR_AWS_HOSTED_REGION
  2. If any commands need to pass into the AWS batch job, mention those inside ContainerOverrides.builder().command() section.
  3. When submitting the job, need to specify a jobName. For that can use any name preferred.
  4. Add the jobQueue that was explicitly created to run this AWS batch job.
  5. Then add the jobDefinition.
  6. If you do not have any commands to pass, you can avoid the ContainnerOverrides section in the 5th line and 11th line.
  7. Pass the parameters if there are any.

Step 4 -

Once you submit the job, it will automatically create a Jobname with the given name in your AWS Batch Jobs section.

Step 5 -

Now all implementations related to integrating AWS Batch Job to a Maven project is completed. If you still need to capture the status changes of this batch job submitted, use the following code to get them. This step is optional.

To capture AWS Batch Job-status add waits before calling this method. If the response.jobSummaryList() is empty, that means the AWS Batch Job is completed running. This is not an indication of whether the Job is Succeeded or Failed, and this indicates that the AWS Batch Job has finished running.

To capture the status, response.jobSummaryList() will give the list of job summary details and there you can see the status as well.

--

--