

# Create a job queue
<a name="create-job-queue"></a>

Before you can submit jobs in AWS Batch, you must create a job queue. When you create a job queue, you associate one or more compute environments to the queue and assign an order of preference.

You also set priority to the job queue that determines the order that the AWS Batch scheduler places jobs. This means that, if a compute environment is associated with more than one job queue, the job queue with a higher priority is given preference.

**Topics**
+ [Create an Amazon EC2 job queue](create-job-queue-ec2.md)
+ [Create a Fargate job queue](create-job-queue-fargate.md)
+ [Create an Amazon EKS job queue](create-job-queue-eks.md)
+ [Create a SageMaker Training job queue in AWS Batch](create-sagemaker-job-queue.md)
+ [Job queue template](job-queue-template.md)

# Create an Amazon EC2 job queue
<a name="create-job-queue-ec2"></a>

Complete the following steps to create a job queue for Amazon Elastic Compute Cloud (Amazon EC2).

**To create an Amazon EC2 job queue**

1. Open the AWS Batch console at [https://console.aws.amazon.com/batch/](https://console.aws.amazon.com/batch/).

1. From the navigation bar, select the AWS Region to use.

1. In the navigation pane, choose **Job queues**.

1. Choose **Create**.

1. For **Orchestration type**, choose **Amazon Elastic Compute Cloud (Amazon EC2)**.

1. For **Name**, enter a unique name for your job queue. The name can be up to 128 characters long, and can contain uppercase and lowercase letters, numbers, and underscores (\$1).

1. For **Priority**, enter an whole number value for the job queue's priority. Job queues with a higher priority are run before lower priority job queues that are associated with the same compute environment. Priority is determined in descending order. For example, a job queue with a priority value of 10 is given scheduling preference over a job queue with a priority value of 1.

1. (Optional) For **Scheduling policy Amazon Resource Name (ARN)**, choose an existing scheduling policy.

1. For **Connected compute environments**, select one or more compute environments from the list to associate with the job queue. Select compute environments in the order that you want the queue to attempt job queue placement. The job scheduler uses the order that you select compute environments in to determine which compute environment starts a given job. Before you can associate them with a job queue, compute environments must be in the `VALID` state. You can associate up to three compute environments with a job queue. If you don't have an existing compute environment, choose **Create compute environment**
**Note**  
All compute environments that are associated with a job queue must share the same provisioning model. AWS Batch doesn't support mixing provisioning models in a single job queue.

1. For **Compute environment order**, choose the up and down arrows to configure order that you want.

1. Choose **Create job queue** to finish and create your job queue.

# Create a Fargate job queue
<a name="create-job-queue-fargate"></a>

Complete the following steps to create a job queue for AWS Fargate.

**To create a Fargate job queue**

1. Open the AWS Batch console at [https://console.aws.amazon.com/batch/](https://console.aws.amazon.com/batch/).

1. From the navigation bar, select the AWS Region to use.

1. In the navigation pane, choose **Job queues**.

1. Choose **Create**.

1. For **Orchestration type**, choose **Fargate**.

1. For **Name**, enter a unique name for your job queue. The name can be up to 128 characters long, and can contain uppercase and lowercase letters, numbers, and underscores (\$1).

1. For **Priority**, enter an whole number value for the job queue's priority. Job queues with a higher priority are run before lower priority job queues that are associated with the same compute environment. Priority is determined in descending order. For example, a job queue with a priority value of 10 is given scheduling preference over a job queue with a priority value of 1.

1. (Optional) For **Scheduling policy Amazon Resource Name (ARN)**, choose an existing scheduling policy.

1. For **Connected compute environments**, select one or more compute environments from the list to associate with the job queue. Select compute environments in the order that you want the queue to attempt job queue placement. The job scheduler uses the order that you select compute environments in to determine which compute environment starts a given job. Before you can associate them with a job queue, compute environments must be in the `VALID` state. You can associate up to three compute environments with a job queue.
**Note**  
All compute environments that are associated with a job queue must share the same provisioning model. AWS Batch doesn't support mixing provisioning models in a single job queue.

1. For **Compute environment order**, choose the up and down arrows to configure order that you want.

1. Choose **Create job queue** to finish and create your job queue.

# Create an Amazon EKS job queue
<a name="create-job-queue-eks"></a>

Complete the following steps to create a job queue for Amazon Elastic Kubernetes Service (Amazon EKS).

**To create an Amazon EKS job queue**

1. Open the AWS Batch console at [https://console.aws.amazon.com/batch/](https://console.aws.amazon.com/batch/).

1. From the navigation bar, select the AWS Region to use.

1. In the navigation pane, choose **Job queues**.

1. Choose **Create**.

1. For **Orchestration type**, choose **Amazon Elastic Kubernetes Service (Amazon EKS)**.

1. For **Name**, enter a unique name for your job queue. The name can be up to 128 characters long, and can contain uppercase and lowercase letters, numbers, and underscores (\$1).

1. For **Priority**, enter an integer value for the job queue's priority. Job queues with a higher priority are run before lower priority job queues that are associated with the same compute environment. Priority is determined in descending order. For example, a job queue with a priority value of 10 is given scheduling preference over a job queue with a priority value of 1.

1. (Optional) For **Scheduling policy Amazon Resource Name (ARN)**, choose an existing scheduling policy.

1. For **Connected compute environments**, select one or more compute environments from the list to associate with the job queue. Select compute environments in the order that you want the queue to attempt job queue placement. The job scheduler uses the order that you select compute environments in to determine which compute environment starts a given job. Before you can associate them with a job queue, compute environments must be in the `VALID` state. You can associate up to three compute environments with a job queue.
**Note**  
All compute environments that are associated with a job queue must share the same provisioning model. AWS Batch doesn't support mixing provisioning models in a single job queue.
**Note**  
All compute environments that are associated with a job queue must share the same architecture. AWS Batch doesn't support mixing compute environment architecture types in a single job queue.

1. For **Compute environment order**, choose the up and down arrows to configure order that you want.

1. Choose **Create job queue** to finish and create your job queue.

# Create a SageMaker Training job queue in AWS Batch
<a name="create-sagemaker-job-queue"></a>

SageMaker Training job queues integrate directly with the SageMaker AI service to provide serverless job scheduling without requiring you to manage underlying compute infrastructure.

## Prerequisites
<a name="sagemaker-job-queue-prerequisites"></a>

Before creating a SageMaker Training job queue, ensure you have:
+ **Service environment** – A service environment that defines capacity limits. For more information, see [Create a service environment in AWS Batch](create-service-environments.md).
+ **IAM permissions** – Permissions to create and manage AWS Batch job queues and service environments. For more information, see [AWS Batch IAM policies, roles, and permissions](IAM_policies.md).

------
#### [ Create a SageMaker Training job queue (AWS Batch console) ]

1. Open the AWS Batch console at [https://console.aws.amazon.com/batch/](https://console.aws.amazon.com/batch/).

1. In the navigation pane, choose **Job queues** and the **Create**.

1. For **Orchestration type**, choose **SageMaker Training**.

1. For **Job queue configuration**:

   1. For **Name**, enter the name of the Job queue.

   1. for **Priority**, enter a value between 0 and 1000. A Job queue with a higher priority is given preference for service environments.

   1. (Optional) For **Scheduling policy Amazon Resource Name (ARN)**, choose an existing scheduling policy.

   1. For **Connected service environments**, select a service environment from the list to associate with the job queue. 

1. (Optional) For **Job state limits**:

   1. For **Misconfiguration**, choose `SERVICE_ENVIRONMENT_MAX_RESOURCE` and enter the **Maximum runnable time (seconds)**.

   1. For **Capacity**, choose `INSUFFICIENT_INSTANCE_CAPACITY` and enter the **Maximum runnable time (seconds)**.

1. Choose **Create job queue**

------
#### [ Create a SageMaker Training job queue (AWS CLI) ]

Use the `create-job-queue` command to create a SageMaker Training job queue.

The following example creates a basic SageMaker Training job queue that uses a service environment:

```
aws batch create-job-queue \
  --job-queue-name my-sm-training-fifo-jq \
  --job-queue-type SAGEMAKER_TRAINING \
  --priority 1 \
  --service-environment-order order=1,serviceEnvironment=ExampleServiceEnvironment
```

Replace *ExampleServiceEnvironment* with the name of your service environment.

The command returns output similar to the following:

```
{
  "jobQueueName": "my-sm-training-fifo-jq",
  "jobQueueArn": "arn:aws:batch:region:account:job-queue/my-sm-training-fifo-jq"
}
```

After creating your job queue, verify that it was created successfully and is in a valid state.

Use the `describe-job-queues` command to view details about your job queue:

```
aws batch describe-job-queues --job-queues my-sm-training-fifo-jq
```

The command returns output similar to the following:

```
{
  "jobQueues": [
    {
      "jobQueueName": "my-sm-training-fifo-jq",
      "jobQueueArn": "arn:aws:batch:region:account:job-queue/my-sm-training-fifo-jq",
      "state": "ENABLED",
      "status": "VALID",
      "statusReason": "JobQueue Healthy",
      "priority": 1,
      "computeEnvironmentOrder": [],
      "serviceEnvironmentOrder": [
        {
          "order": 1,
          "serviceEnvironment": "arn:aws:batch:region:account:service-environment/ExampleServiceEnvironment"
        }
      ],
      "jobQueueType": "SAGEMAKER_TRAINING",
      "tags": {},
      "jobStateTimeLimitActions": []
    }
  ]
}
```

Ensure that:
+ The `state` is `ENABLED`
+ The `status` is `VALID`
+ The `statusReason` is `JobQueue Healthy`
+ The `jobQueueType` is `SAGEMAKER_TRAINING`
+ The `serviceEnvironmentOrder` references your service environment

------

# Job queue template
<a name="job-queue-template"></a>

The following is an empty job queue template. You can use this template to create your job queue. You can then save this job queue to a file and use it with the AWS CLI `--cli-input-json` option. For more information about these parameters, see [CreateJobQueue](https://docs.aws.amazon.com/batch/latest/APIReference/API_CreateJobQueue.html) in the *AWS Batch API Reference*.

**Note**  
You can generate a job queue template with the following AWS CLI command.  

```
$ aws batch create-job-queue --generate-cli-skeleton
```

```
{
   "computeEnvironmentOrder": [ 
      { 
         "computeEnvironment": "",
         "order": 0
      }
   ],
   "jobQueueName": "",
   "jobStateTimeLimitActions": [ 
      { 
         "state": "RUNNABLE",
         "action": "CANCEL",
		 "maxTimeSeconds": 0,
         "reason": ""

      }
   ],
   "priority": 0,
   "schedulingPolicyArn": "",
   "state": "ENABLED",
   "tags": { 
      "KeyName": ""
   }
}
```