title: How to use AWS batch in java class(lambda function) to submit batch job
body: <p>I read the output from stepfunctions  using envContainerOverrides and  then I am calling my batch job with this nodejscode: Here I am reading the environment variables which is passed to the batchjob.</p>
  
  <p>Stepfunctions output:</p>
  
  <pre><code>{"bucketName":"bucketName","filesList":["filelist-bucket/filelist1.txt","filelist-bucket/filelist2.txt"]}
  </code></pre>
  
  <p>This nodejs code is not able to fetch if its an  array [filelist-bucket/filelist1.txt","filelist-bucket/filelist2.txt] it works perfectly if its a single value.</p>
  
  <p>I want to convert this nodejs code into java :</p>
  
  <pre><code>'use strict';
  
  const AWS = require('aws-sdk');
  
  console.log('Loading function');
  
  exports.handler = (event, context, callback) =&gt; {
      // Take the data from step 1 and modify, send to standard output
      var comment = event.Comment ;
  
      var envContainerOverrides ={
          "environment" :[
            {
             "name":"s3Bucket",
             "value":event.bucketName
            },
            {
             "name":"s3FileList",
             "value":event.filesListUrl
            }
          ]
      };
      const params = {
          jobDefinition: process.env.JOB_DEFINITION,
          jobName: process.env.JOB_NAME,
          jobQueue:process.env.JOB_QUEUE,
          containerOverrides: envContainerOverrides || null,
          parameters: event.parameters || null,
      };
  
  
      // Submit the Batch Job
      new AWS.Batch().submitJob(params, (err, data) =&gt; {
          if (err) {
              console.error(err);
              const message = `Error calling SubmitJob for: ${event.jobName}`;
              console.error(message);
              callback(message);
          } else {
              const jobId = data.jobId;
              console.log('jobId:', jobId);
              callback(null, "Job Id : "+jobId);
          }
      });
  
  
  
  };
  </code></pre>
  
  <p>I am doing something like this:</p>
  
  <pre><code>public class InitiateBatchJob1 {
  
      public static BatchJobRequest process(BatchJobRequest batchJobRequest) throws Exception {
  
  
          String s3Bucket = batchJobRequest.getBucketName();
          List&lt;String&gt; s3FileList = batchJobRequest.getFilesListUrl();
  
          Job job = new Job();
          job.setJobDefinition("testbatchjobenv:2");
          job.setJobQueue("nbatchjobqueue");
          job.setJobName("Filedownload");
  
  
          /*// Submit the Batch Job
          new AWS.Batch().submitJob(params, (err, data) =&gt; {
              if (err) {
                  console.error(err);
                  const message = `Error calling SubmitJob for: ${event.jobName}`;
                  console.error(message);
                  callback(message);
              } else {
                  const jobId = data.jobId;
                  console.log('jobId:', jobId);
                  callback(null, "Job Id : "+jobId);
              }
          });
  */
  
  
  
          return null;
      }
  
  
  }
  </code></pre>
  
  <p>BatchJobRequest.java</p>
  
  <pre><code>import java.util.List;
  
  public class BatchJobRequest {
  
      private String bucketName;
  
      private List&lt;String&gt; filesListUrl;
  
      public String getBucketName() {
          return bucketName;
      }
  
      public void setBucketName(String bucketName) {
          this.bucketName = bucketName;
      }
  
      public List&lt;String&gt; getFilesListUrl() {
          return filesListUrl;
      }
  
      public void setFilesListUrl(List&lt;String&gt; filesListUrl) {
          this.filesListUrl = filesListUrl;
      }
  
  }
  </code></pre>
  
  <p>Job.java:</p>
  
  <pre><code>public class Job {
  
      private String jobDefinition;
      private String jobName;
      private String jobQueue;
      private String containerOverrides;
      private String parameters;
      public String getJobDefinition() {
          return jobDefinition;
      }
      public void setJobDefinition(String jobDefinition) {
          this.jobDefinition = jobDefinition;
      }
      public String getJobName() {
          return jobName;
      }
      public void setJobName(String jobName) {
          this.jobName = jobName;
      }
      public String getJobQueue() {
          return jobQueue;
      }
      public void setJobQueue(String jobQueue) {
          this.jobQueue = jobQueue;
      }
      public String getContainerOverrides() {
          return containerOverrides;
      }
      public void setContainerOverrides(String containerOverrides) {
          this.containerOverrides = containerOverrides;
      }
      public String getParameters() {
          return parameters;
      }
      public void setParameters(String parameters) {
          this.parameters = parameters;
      }
  
  
  }
  </code></pre>
  
  <p>and I have found this api for AWSBatch 
  <a href="http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/batch/AWSBatch.html#cancelJob-com.amazonaws.services.batch.model.CancelJobRequest-" rel="nofollow noreferrer">http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/batch/AWSBatch.html#cancelJob-com.amazonaws.services.batch.model.CancelJobRequest-</a></p>
  
  <p>But not sure if its the correct api to use in my class.I searched online  there isnt much links on using aws batch in java.</p>
  
  <p>Basically I need to know how to  set job denfition,jobName,job queue and submit batchjob using java class .Can anyone please help me with this.</p>