Skip to content

create_job_queue async

create_job_queue(
    *,
    config_overrides: Optional[AsyncBatchClientConfig] = None,
    job_queue_name: Optional[String] = None,
    state: Optional[JQState] = None,
    scheduling_policy_arn: Optional[String] = None,
    priority: Optional[Integer] = None,
    compute_environment_order: Optional[ComputeEnvironmentOrders] = None,
    service_environment_order: Optional[ServiceEnvironmentOrders] = None,
    job_queue_type: Optional[JobQueueType] = None,
    tags: Optional[TagrisTagsMap] = None,
    job_state_time_limit_actions: Optional[JobStateTimeLimitActions] = None,
) -> CreateJobQueueResponse

Creates an Batch job queue. When you create a job queue, you associate one or more compute environments to the queue and assign an order of preference for the compute environments.

You also set a priority to the job queue that determines the order that the Batch scheduler places jobs onto its associated compute environments. For example, if a compute environment is associated with more than one job queue, the job queue with a higher priority is given preference for scheduling jobs to that compute environment.

Parameters:

  • job_queue_name (Optional[String], default: None ) –

    The name of the job queue. It can be up to 128 letters long. It can contain uppercase and lowercase letters, numbers, hyphens (-), and underscores (_).

  • state (Optional[JQState], default: None ) –

    The state of the job queue. If the job queue state is ENABLED, it is able to accept jobs. If the job queue state is DISABLED, new jobs can't be added to the queue, but jobs already in the queue can finish.

  • scheduling_policy_arn (Optional[String], default: None ) –

    The Amazon Resource Name (ARN) of the fair-share scheduling policy. Job queues that don't have a fair-share scheduling policy are scheduled in a first-in, first-out (FIFO) model. After a job queue has a fair-share scheduling policy, it can be replaced but can't be removed.

    The format is aws:Partition:batch:Region:Account:scheduling-policy/Name .

    An example is aws:aws:batch:us-west-2:123456789012:scheduling-policy/MySchedulingPolicy.

    A job queue without a fair-share scheduling policy is scheduled as a FIFO job queue and can't have a fair-share scheduling policy added. Jobs queues with a fair-share scheduling policy can have a maximum of 500 active share identifiers. When the limit has been reached, submissions of any jobs that add a new share identifier fail.

  • priority (Optional[Integer], default: None ) –

    The priority of the job queue. Job queues with a higher priority (or a higher integer value for the priority parameter) are evaluated first when 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. All of the compute environments must be either EC2 (EC2 or SPOT) or Fargate (FARGATE or FARGATE_SPOT); EC2 and Fargate compute environments can't be mixed.

  • compute_environment_order (Optional[ComputeEnvironmentOrders], default: None ) –

    The set of compute environments mapped to a job queue and their order relative to each other. The job scheduler uses this parameter to determine which compute environment runs a specific job. Compute environments must be in the VALID state before you can associate them with a job queue. You can associate up to three compute environments with a job queue. All of the compute environments must be either EC2 (EC2 or SPOT) or Fargate (FARGATE or FARGATE_SPOT); EC2 and Fargate compute environments can't be mixed.

    All compute environments that are associated with a job queue must share the same architecture. Batch doesn't support mixing compute environment architecture types in a single job queue.

  • service_environment_order (Optional[ServiceEnvironmentOrders], default: None ) –

    A list of service environments that this job queue can use to allocate jobs. All serviceEnvironments must have the same type. A job queue can't have both a serviceEnvironmentOrder and a computeEnvironmentOrder field.

  • job_queue_type (Optional[JobQueueType], default: None ) –

    The type of job queue. For service jobs that run on SageMaker Training, this value is SAGEMAKER_TRAINING. For regular container jobs, this value is EKS, ECS, or ECS_FARGATE depending on the compute environment.

  • tags (Optional[TagrisTagsMap], default: None ) –

    The tags that you apply to the job queue to help you categorize and organize your resources. Each tag consists of a key and an optional value. For more information, see Tagging your Batch resources in Batch User Guide.

  • job_state_time_limit_actions (Optional[JobStateTimeLimitActions], default: None ) –

    The set of actions that Batch performs on jobs that remain at the head of the job queue in the specified state longer than specified times. Batch will perform each action after maxTimeSeconds has passed. (Note: The minimum value for maxTimeSeconds is 600 (10 minutes) and its maximum value is 86,400 (24 hours).)

Raises:

  • ClientException –

    These errors are usually caused by a client action. One example cause is using an action or resource on behalf of a user that doesn't have permissions to use the action or resource. Another cause is specifying an identifier that's not valid.

  • ServerException –

    These errors are usually caused by a server issue.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Examples:

To create a job queue with a single compute environment This example creates a job queue called LowPriority that uses the M4Spot compute environment.

>>> await client.create_job_queue(priority=1, state='ENABLED', compute_environment_order=[{'computeEnvironment': 'M4Spot', 'order': 1}], job_queue_name='LowPriority')
To create a job queue with an ECS Managed Instances compute environment
This example creates a job queue called ManagedInstancesQueue that uses an ECS Managed Instances compute environment.
>>> await client.create_job_queue(priority=10, state='ENABLED', compute_environment_order=[{'computeEnvironment': 'my-managed-instances-ce', 'order': 1}], job_queue_name='ManagedInstancesQueue')
To create a job queue with multiple compute environments
This example creates a job queue called HighPriority that uses the C4OnDemand compute environment with an order of 1 and the M4Spot compute environment with an order of 2.
>>> await client.create_job_queue(priority=10, state='ENABLED', compute_environment_order=[{'computeEnvironment': 'C4OnDemand', 'order': 1}, {'computeEnvironment': 'M4Spot', 'order': 2}], job_queue_name='HighPriority')
To create a job queue with On-Demand and Spot ECS Managed Instances compute environments
This example creates a job queue that uses both On-Demand and Spot ECS Managed Instances compute environments. On-Demand environments must be ordered before Spot environments.
>>> await client.create_job_queue(priority=5, state='ENABLED', compute_environment_order=[{'computeEnvironment': 'my-managed-instances-ce', 'order': 1}, {'computeEnvironment': 'my-spot-managed-instances-ce', 'order': 2}], job_queue_name='ManagedInstancesMixedQueue')
Source code in docs_src/capo_batch/_services/async_batch.py
async def create_job_queue(
    self,
    *,
    config_overrides: Optional[AsyncBatchClientConfig] = None,
    job_queue_name: Optional["capo_batch.types.string.String"] = None,
    state: Optional["capo_batch.types.jq_state.JQState"] = None,
    scheduling_policy_arn: Optional["capo_batch.types.string.String"] = None,
    priority: Optional["capo_batch.types.integer.Integer"] = None,
    compute_environment_order: Optional[
        "capo_batch.types.compute_environment_orders.ComputeEnvironmentOrders"
    ] = None,
    service_environment_order: Optional[
        "capo_batch.types.service_environment_orders.ServiceEnvironmentOrders"
    ] = None,
    job_queue_type: Optional["capo_batch.types.job_queue_type.JobQueueType"] = None,
    tags: Optional["capo_batch.types.tagris_tags_map.TagrisTagsMap"] = None,
    job_state_time_limit_actions: Optional[
        "capo_batch.types.job_state_time_limit_actions.JobStateTimeLimitActions"
    ] = None,
) -> "capo_batch.types.create_job_queue_response.CreateJobQueueResponse":
    """<p>Creates an Batch job queue. When you create a job queue, you associate one or more compute environments to the queue and assign an order of preference for the compute environments.</p> <p>You also set a priority to the job queue that determines the order that the Batch scheduler places jobs onto its associated compute environments. For example, if a compute environment is associated with more than one job queue, the job queue with a higher priority is given preference for scheduling jobs to that compute environment.</p>

    Args:
        job_queue_name: <p>The name of the job queue. It can be up to 128 letters long. It can contain uppercase and lowercase letters, numbers, hyphens (-), and underscores (_).</p>
        state: <p>The state of the job queue. If the job queue state is <code>ENABLED</code>, it is able to accept jobs. If the job queue state is <code>DISABLED</code>, new jobs can't be added to the queue, but jobs already in the queue can finish.</p>
        scheduling_policy_arn: <p>The Amazon Resource Name (ARN) of the fair-share scheduling policy. Job queues that don't have a fair-share scheduling policy are scheduled in a first-in, first-out (FIFO) model. After a job queue has a fair-share scheduling policy, it can be replaced but can't be removed.</p> <p>The format is <code>aws:<i>Partition</i>:batch:<i>Region</i>:<i>Account</i>:scheduling-policy/<i>Name</i> </code>.</p> <p>An example is <code>aws:aws:batch:us-west-2:123456789012:scheduling-policy/MySchedulingPolicy</code>.</p> <p>A job queue without a fair-share scheduling policy is scheduled as a FIFO job queue and can't have a fair-share scheduling policy added. Jobs queues with a fair-share scheduling policy can have a maximum of 500 active share identifiers. When the limit has been reached, submissions of any jobs that add a new share identifier fail.</p>
        priority: <p>The priority of the job queue. Job queues with a higher priority (or a higher integer value for the <code>priority</code> parameter) are evaluated first when associated with the same compute environment. Priority is determined in descending order. For example, a job queue with a priority value of <code>10</code> is given scheduling preference over a job queue with a priority value of <code>1</code>. All of the compute environments must be either EC2 (<code>EC2</code> or <code>SPOT</code>) or Fargate (<code>FARGATE</code> or <code>FARGATE_SPOT</code>); EC2 and Fargate compute environments can't be mixed.</p>
        compute_environment_order: <p>The set of compute environments mapped to a job queue and their order relative to each other. The job scheduler uses this parameter to determine which compute environment runs a specific job. Compute environments must be in the <code>VALID</code> state before you can associate them with a job queue. You can associate up to three compute environments with a job queue. All of the compute environments must be either EC2 (<code>EC2</code> or <code>SPOT</code>) or Fargate (<code>FARGATE</code> or <code>FARGATE_SPOT</code>); EC2 and Fargate compute environments can't be mixed.</p> <note> <p>All compute environments that are associated with a job queue must share the same architecture. Batch doesn't support mixing compute environment architecture types in a single job queue.</p> </note>
        service_environment_order: <p>A list of service environments that this job queue can use to allocate jobs. All serviceEnvironments must have the same type. A job queue can't have both a serviceEnvironmentOrder and a computeEnvironmentOrder field.</p>
        job_queue_type: <p>The type of job queue. For service jobs that run on SageMaker Training, this value is <code>SAGEMAKER_TRAINING</code>. For regular container jobs, this value is <code>EKS</code>, <code>ECS</code>, or <code>ECS_FARGATE</code> depending on the compute environment.</p>
        tags: <p>The tags that you apply to the job queue to help you categorize and organize your resources. Each tag consists of a key and an optional value. For more information, see <a href="https://docs.aws.amazon.com/batch/latest/userguide/using-tags.html">Tagging your Batch resources</a> in <i>Batch User Guide</i>.</p>
        job_state_time_limit_actions: <p>The set of actions that Batch performs on jobs that remain at the head of the job queue in the specified state longer than specified times. Batch will perform each action after <code>maxTimeSeconds</code> has passed. (<b>Note</b>: The minimum value for maxTimeSeconds is 600 (10 minutes) and its maximum value is 86,400 (24 hours).)</p>

    Raises:
        capo_batch.errors.client_exception.ClientException: <p>These errors are usually caused by a client action. One example cause is using an action or resource on behalf of a user that doesn't have permissions to use the action or resource. Another cause is specifying an identifier that's not valid.</p>
        capo_batch.errors.server_exception.ServerException: <p>These errors are usually caused by a server issue.</p>
        capo_batch.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To create a job queue with a single compute environment
        This example creates a job queue called LowPriority that uses the M4Spot compute environment.

        >>> await client.create_job_queue(priority=1, state='ENABLED', compute_environment_order=[{'computeEnvironment': 'M4Spot', 'order': 1}], job_queue_name='LowPriority')
        To create a job queue with an ECS Managed Instances compute environment
        This example creates a job queue called ManagedInstancesQueue that uses an ECS Managed Instances compute environment.

        >>> await client.create_job_queue(priority=10, state='ENABLED', compute_environment_order=[{'computeEnvironment': 'my-managed-instances-ce', 'order': 1}], job_queue_name='ManagedInstancesQueue')
        To create a job queue with multiple compute environments
        This example creates a job queue called HighPriority that uses the C4OnDemand compute environment with an order of 1 and the M4Spot compute environment with an order of 2.

        >>> await client.create_job_queue(priority=10, state='ENABLED', compute_environment_order=[{'computeEnvironment': 'C4OnDemand', 'order': 1}, {'computeEnvironment': 'M4Spot', 'order': 2}], job_queue_name='HighPriority')
        To create a job queue with On-Demand and Spot ECS Managed Instances compute environments
        This example creates a job queue that uses both On-Demand and Spot ECS Managed Instances compute environments. On-Demand environments must be ordered before Spot environments.

        >>> await client.create_job_queue(priority=5, state='ENABLED', compute_environment_order=[{'computeEnvironment': 'my-managed-instances-ce', 'order': 1}, {'computeEnvironment': 'my-spot-managed-instances-ce', 'order': 2}], job_queue_name='ManagedInstancesMixedQueue')
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_batch.types.create_job_queue_request.CreateJobQueueRequest]",
    ) -> AsyncOperationResponse[
        "capo_batch.types.create_job_queue_response.CreateJobQueueResponse"
    ]:
        import capo_batch._operations.aws_batch_v20160810.create_job_queue

        (
            output,
            http_response,
        ) = await capo_batch._operations.aws_batch_v20160810.create_job_queue.async_create_job_queue(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateJobQueue")
    )
    input_: capo_batch.types.create_job_queue_request.CreateJobQueueRequest = {}
    if job_queue_name is not None:
        input_["job_queue_name"] = job_queue_name
    if state is not None:
        input_["state"] = state
    if scheduling_policy_arn is not None:
        input_["scheduling_policy_arn"] = scheduling_policy_arn
    if priority is not None:
        input_["priority"] = priority
    if compute_environment_order is not None:
        input_["compute_environment_order"] = compute_environment_order
    if service_environment_order is not None:
        input_["service_environment_order"] = service_environment_order
    if job_queue_type is not None:
        input_["job_queue_type"] = job_queue_type
    if tags is not None:
        input_["tags"] = tags
    if job_state_time_limit_actions is not None:
        input_["job_state_time_limit_actions"] = job_state_time_limit_actions

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output