You are viewing documentation for version 2 of the AWS SDK for Ruby. Version 3 documentation can be found here.
Class: Aws::Batch::Client
- Inherits:
-
Seahorse::Client::Base
- Object
- Seahorse::Client::Base
- Aws::Batch::Client
- Defined in:
- (unknown)
Overview
An API client for AWS Batch. To construct a client, you need to configure a :region
and :credentials
.
batch = Aws::Batch::Client.new(
region: region_name,
credentials: credentials,
# ...
)
See #initialize for a full list of supported configuration options.
Region
You can configure a default region in the following locations:
ENV['AWS_REGION']
Aws.config[:region]
Go here for a list of supported regions.
Credentials
Default credentials are loaded automatically from the following locations:
ENV['AWS_ACCESS_KEY_ID']
andENV['AWS_SECRET_ACCESS_KEY']
Aws.config[:credentials]
- The shared credentials ini file at
~/.aws/credentials
(more information) - From an instance profile when running on EC2
You can also construct a credentials object from one of the following classes:
Alternatively, you configure credentials with :access_key_id
and
:secret_access_key
:
# load credentials from disk
creds = YAML.load(File.read('/path/to/secrets'))
Aws::Batch::Client.new(
access_key_id: creds['access_key_id'],
secret_access_key: creds['secret_access_key']
)
Always load your credentials from outside your application. Avoid configuring credentials statically and never commit them to source control.
Instance Attribute Summary
Attributes inherited from Seahorse::Client::Base
Constructor collapse
-
#initialize(options = {}) ⇒ Aws::Batch::Client
constructor
Constructs an API client.
API Operations collapse
-
#cancel_job(options = {}) ⇒ Struct
Cancels a job in an AWS Batch job queue.
-
#create_compute_environment(options = {}) ⇒ Types::CreateComputeEnvironmentResponse
Creates an AWS Batch compute environment.
-
#create_job_queue(options = {}) ⇒ Types::CreateJobQueueResponse
Creates an AWS Batch job queue.
-
#delete_compute_environment(options = {}) ⇒ Struct
Deletes an AWS Batch compute environment.
Before you can delete a compute environment, you must set its state to
.DISABLED
with the UpdateComputeEnvironment API operation and disassociate it from any job queues with the UpdateJobQueue API operation. -
#delete_job_queue(options = {}) ⇒ Struct
Deletes the specified job queue.
-
#deregister_job_definition(options = {}) ⇒ Struct
Deregisters an AWS Batch job definition.
-
#describe_compute_environments(options = {}) ⇒ Types::DescribeComputeEnvironmentsResponse
Describes one or more of your compute environments.
If you are using an unmanaged compute environment, you can use the
.DescribeComputeEnvironment
operation to determine theecsClusterArn
that you should launch your Amazon ECS container instances into. -
#describe_job_definitions(options = {}) ⇒ Types::DescribeJobDefinitionsResponse
Describes a list of job definitions.
-
#describe_job_queues(options = {}) ⇒ Types::DescribeJobQueuesResponse
Describes one or more of your job queues.
.
-
#describe_jobs(options = {}) ⇒ Types::DescribeJobsResponse
Describes a list of AWS Batch jobs.
.
-
#list_jobs(options = {}) ⇒ Types::ListJobsResponse
Returns a list of AWS Batch jobs.
You must specify only one of the following:
-
a job queue ID to return a list of jobs in that job queue
-
a multi-node parallel job ID to return a list of that job's nodes
-
an array job ID to return a list of that job's children
You can filter the results by job status with the
jobStatus
parameter. -
-
#list_tags_for_resource(options = {}) ⇒ Types::ListTagsForResourceResponse
List the tags for an AWS Batch resource.
-
#register_job_definition(options = {}) ⇒ Types::RegisterJobDefinitionResponse
Registers an AWS Batch job definition.
.
-
#submit_job(options = {}) ⇒ Types::SubmitJobResponse
Submits an AWS Batch job from a job definition.
-
#tag_resource(options = {}) ⇒ Struct
Associates the specified tags to a resource with the specified
resourceArn
. -
#terminate_job(options = {}) ⇒ Struct
Terminates a job in a job queue.
-
#untag_resource(options = {}) ⇒ Struct
Deletes specified tags from an AWS Batch resource.
.
-
#update_compute_environment(options = {}) ⇒ Types::UpdateComputeEnvironmentResponse
Updates an AWS Batch compute environment.
.
-
#update_job_queue(options = {}) ⇒ Types::UpdateJobQueueResponse
Updates a job queue.
.
Instance Method Summary collapse
-
#wait_until(waiter_name, params = {}) {|waiter| ... } ⇒ Boolean
Waiters polls an API operation until a resource enters a desired state.
-
#waiter_names ⇒ Array<Symbol>
Returns the list of supported waiters.
Methods inherited from Seahorse::Client::Base
add_plugin, api, #build_request, clear_plugins, define, new, #operation, #operation_names, plugins, remove_plugin, set_api, set_plugins
Methods included from Seahorse::Client::HandlerBuilder
#handle, #handle_request, #handle_response
Constructor Details
#initialize(options = {}) ⇒ Aws::Batch::Client
Constructs an API client.
Instance Method Details
#cancel_job(options = {}) ⇒ Struct
Cancels a job in an AWS Batch job queue. Jobs that are in the SUBMITTED
, PENDING
, or RUNNABLE
state are cancelled. Jobs that have progressed to STARTING
or RUNNING
are not cancelled (but the API operation still succeeds, even if no job is cancelled); these jobs must be terminated with the TerminateJob operation.
#create_compute_environment(options = {}) ⇒ Types::CreateComputeEnvironmentResponse
Creates an AWS Batch compute environment. You can create MANAGED
or UNMANAGED
compute environments.
In a managed compute environment, AWS Batch manages the capacity and instance types of the compute resources within the environment. This is based on the compute resource specification that you define or the launch template that you specify when you create the compute environment. You can choose to use Amazon EC2 On-Demand Instances or Spot Instances in your managed compute environment. You can optionally set a maximum price so that Spot Instances only launch when the Spot Instance price is below a specified percentage of the On-Demand price.
Multi-node parallel jobs are not supported on Spot Instances.
In an unmanaged compute environment, you can manage your own compute resources. This provides more compute resource configuration options, such as using a custom AMI, but you must ensure that your AMI meets the Amazon ECS container instance AMI specification. For more information, see Container Instance AMIs in the Amazon Elastic Container Service Developer Guide. After you have created your unmanaged compute environment, you can use the DescribeComputeEnvironments operation to find the Amazon ECS cluster that is associated with it. Then, manually launch your container instances into that Amazon ECS cluster. For more information, see Launching an Amazon ECS Container Instance in the Amazon Elastic Container Service Developer Guide.
AWS Batch does not upgrade the AMIs in a compute environment after it is created (for example, when a newer version of the Amazon ECS-optimized AMI is available). You are responsible for the management of the guest operating system (including updates and security patches) and any additional application software or utilities that you install on the compute resources. To use a new AMI for your AWS Batch jobs:
-
Create a new compute environment with the new AMI.
-
Add the compute environment to an existing job queue.
-
Remove the old compute environment from your job queue.
-
Delete the old compute environment.
#create_job_queue(options = {}) ⇒ Types::CreateJobQueueResponse
Creates an AWS 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 in which the AWS 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.
#delete_compute_environment(options = {}) ⇒ Struct
Deletes an AWS Batch compute environment.
Before you can delete a compute environment, you must set its state to DISABLED
with the UpdateComputeEnvironment API operation and disassociate it from any job queues with the UpdateJobQueue API operation.
#delete_job_queue(options = {}) ⇒ Struct
Deletes the specified job queue. You must first disable submissions for a queue with the UpdateJobQueue operation. All jobs in the queue are terminated when you delete a job queue.
It is not necessary to disassociate compute environments from a queue before submitting a DeleteJobQueue
request.
#deregister_job_definition(options = {}) ⇒ Struct
Deregisters an AWS Batch job definition. Job definitions will be permanently deleted after 180 days.
#describe_compute_environments(options = {}) ⇒ Types::DescribeComputeEnvironmentsResponse
Describes one or more of your compute environments.
If you are using an unmanaged compute environment, you can use the DescribeComputeEnvironment
operation to determine the ecsClusterArn
that you should launch your Amazon ECS container instances into.
#describe_job_definitions(options = {}) ⇒ Types::DescribeJobDefinitionsResponse
Describes a list of job definitions. You can specify a status
(such as ACTIVE
) to only return job definitions that match that status.
#describe_job_queues(options = {}) ⇒ Types::DescribeJobQueuesResponse
Describes one or more of your job queues.
#describe_jobs(options = {}) ⇒ Types::DescribeJobsResponse
Describes a list of AWS Batch jobs.
#list_jobs(options = {}) ⇒ Types::ListJobsResponse
Returns a list of AWS Batch jobs.
You must specify only one of the following:
-
a job queue ID to return a list of jobs in that job queue
-
a multi-node parallel job ID to return a list of that job's nodes
-
an array job ID to return a list of that job's children
You can filter the results by job status with the jobStatus
parameter. If you do not specify a status, only RUNNING
jobs are returned.
#list_tags_for_resource(options = {}) ⇒ Types::ListTagsForResourceResponse
List the tags for an AWS Batch resource. AWS Batch resources that support tags are compute environments, jobs, job definitions, and job queues. ARNs for child jobs of array and multi-node parallel (MNP) jobs are not supported.
#register_job_definition(options = {}) ⇒ Types::RegisterJobDefinitionResponse
Registers an AWS Batch job definition.
#submit_job(options = {}) ⇒ Types::SubmitJobResponse
Submits an AWS Batch job from a job definition. Parameters specified during SubmitJob override parameters defined in the job definition.
#tag_resource(options = {}) ⇒ Struct
Associates the specified tags to a resource with the specified resourceArn
. If existing tags on a resource are not specified in the request parameters, they are not changed. When a resource is deleted, the tags associated with that resource are deleted as well. AWS Batch resources that support tags are compute environments, jobs, job definitions, and job queues. ARNs for child jobs of array and multi-node parallel (MNP) jobs are not supported.
#terminate_job(options = {}) ⇒ Struct
Terminates a job in a job queue. Jobs that are in the STARTING
or RUNNING
state are terminated, which causes them to transition to FAILED
. Jobs that have not progressed to the STARTING
state are cancelled.
#untag_resource(options = {}) ⇒ Struct
Deletes specified tags from an AWS Batch resource.
#update_compute_environment(options = {}) ⇒ Types::UpdateComputeEnvironmentResponse
Updates an AWS Batch compute environment.
#update_job_queue(options = {}) ⇒ Types::UpdateJobQueueResponse
Updates a job queue.
#wait_until(waiter_name, params = {}) {|waiter| ... } ⇒ Boolean
Waiters polls an API operation until a resource enters a desired state.
Basic Usage
Waiters will poll until they are succesful, they fail by entering a terminal state, or until a maximum number of attempts are made.
# polls in a loop, sleeping between attempts client.waiter_until(waiter_name, params)
Configuration
You can configure the maximum number of polling attempts, and the delay (in seconds) between each polling attempt. You configure waiters by passing a block to #wait_until:
# poll for ~25 seconds
client.wait_until(...) do |w|
w.max_attempts = 5
w.delay = 5
end
Callbacks
You can be notified before each polling attempt and before each
delay. If you throw :success
or :failure
from these callbacks,
it will terminate the waiter.
started_at = Time.now
client.wait_until(...) do |w|
# disable max attempts
w.max_attempts = nil
# poll for 1 hour, instead of a number of attempts
w.before_wait do |attempts, response|
throw :failure if Time.now - started_at > 3600
end
end
Handling Errors
When a waiter is successful, it returns true
. When a waiter
fails, it raises an error. All errors raised extend from
Waiters::Errors::WaiterFailed.
begin
client.wait_until(...)
rescue Aws::Waiters::Errors::WaiterFailed
# resource did not enter the desired state in time
end
#waiter_names ⇒ Array<Symbol>
Returns the list of supported waiters. The following table lists the supported waiters and the client method they call:
Waiter Name | Client Method | Default Delay: | Default Max Attempts: |
---|