"Guide to terminating an AWS Batch job that is in a RUNNABLE state using the JavaScript SDK

I need assistance with canceling a job stuck in runnable status on AWS Batch using the JavaScript SDK. Which API option should I choose?

1. The TerminateJobCommand documentation states that it terminates jobs in the STARTING or RUNNING state, causing them to transition to FAILED. Jobs not yet in the STARTING state are canceled as well. Since RUNNABLE status comes before STARTING, would TerminateJobCommand be the right choice?

2. The documentation for CancelJobCommand mentions that a job in RUNNABLE remains there until it reaches the front of the queue, at which point its status changes to FAILED. Does this mean CancelJobCommand could also handle cancellations, albeit with some delay?

My testing experience includes using both CancelJobCommand and TerminateJobCommand on the same runnable job, resulting in a 200 status response each time. However, occasionally, when checking with "aws batch list-jobs --job-status RUNNABLE --region XXXX" to confirm if the target jobs were successfully removed from the RUNNABLE list (i.e., canceled), they still appeared in the list as RUNNABLE even after hours.

Answer â„–1

Should jobs that have not progressed to the STARTING state be cancelled since RUNNABLE status comes before STARTING status?

Indeed, for jobs still in the queue, using TerminateJob essentially equals using CancelJob.

Would CancelJobCommand also work for cancelling, albeit with some delay?

There is no delay per se; once you successfully issue the command, the job will never execute. It will remain in a RUNNABLE state but transition directly to FAILED when its execution time arrives.

While batch jobs typically incorporate a retry mechanism to return them to a RUNNABLE state after numerous failed attempts, CancelJob supersedes this behavior.

In the output of the DescribeJobs function, flags like isCancelled and isTerminated indicate if a runnable job will never run as intended.


Note that the term "the head of the queue" can be misleading. Job status transitions from RUNNABLE to STARTING (or FAILED if canceled) just before assignment to a compute unit in the cluster. While being at the front of the queue is one condition, it's not the sole determining factor.

If your job requires 4G of memory but your EC2 instances only offer 2G, the job will remain perpetually in a RUNNABLE state due to mismatched cluster specifications.

The underlying job queue likely leverages an event streaming platform, possibly Kinesis. In event streaming, events are immutable and proceed through processing once on the stream—hence why they persist in the queue.

The status of cancelled or terminated jobs is usually stored elsewhere (e.g., DynamoDB). Until recently, AWS did not expose this information, but now they do.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Assign a predetermined value to a dropdown list within a FormGroup

I have received 2 sets of data from my API: { "content": [{ "id": 1, "roleName": "admin", }, { "id": 2, "roleName": "user", }, { "id": 3, "roleName": "other", } ], "last": true, "totalEleme ...

What is the issue with undefined params in Next.js?

I have come across an issue with the function in app/api/hello/[slug]/route.ts When I try to log the output, it keeps showing as undefined. Why is this happening? The code snippet from app/api/hello/[slug]/route.ts is shown below: export async function G ...

Using jQuery to replace an HTML element multiple times

Seeking assistance for implementing functionality that replaces a button with an input field, where users can enter information and hit enter. Once the action is completed, the original button should reappear. The current script works effectively but lacks ...

What is the process of implementing a page change using a GET request in JavaScript using Node.js and Express?

Within this application, users are provided with a table where they can input data. Each row in the table is equipped with an "Edit" button that, when clicked, should redirect them to a new page labeled "/update" where modifications to the specific row can ...

What yields greater performance in MongoDB: employing multiple indexes or creating multiple collections?

Currently, I am developing an application that validates users through various 3rd party services such as Facebook and Google. Each user is assigned a unique internal id (uuid v4) which corresponds to their 3rd party ids. The mongoose schema for my user do ...

How to upload an Image to Cloudinary using Express.js, React, and Axios for a POST

I encountered an issue while attempting to upload images to Cloudinary using a React front-end and Express server. The problem lies in not being able to properly post request the image to my Express server. Here is how I prepare the image for sending it l ...

Modifying URLs with backbone.js

When it comes to my Backbone module, I typically access it via the URL: http://localhost/src/index.html#test_module However, there is another module that I need to view which can be accessed using the URL: http://localhost/src/index.html#test_module ...

Guidelines for dynamically switching between two buttons (function/text) depending on an external factor (such as the number of items bought)

I'm exploring a previous concept of toggling between two buttons conditionally in a CRA. import ... const ... export const Index = () => { // Setting up boolean state to toggle buttons conditionally const [reachMax] = React.useState(id <= ...

Tips to prevent the webpage from scrolling to the top when clicking on an anchor with an ID

I have developed a CSS/HTML carousel that consists of 4 slides. The goal is to display the selected slide when clicking on the bottom button (a href). However, I am facing an issue where every time I click on a link, the selected slide appears as intended ...

Closing notifications in Bootstrap 5.1 with the help of Ajax

I am utilizing bootstrap 5.1 alerts to display custom messages after an Ajax call. I also want the ability to dismiss the alert as necessary, which can be done with a dismiss button provided by bootstrap. Below is the PHP code I am using : <div class=& ...

Ways to discover the titles of every sub-directory

Suppose I have the absolute path of a directory. Is there a method in JavaScript (Node.js) to determine how many sub-directories it has, and retrieve the names of all its sub-directories? I searched online but didn't come across any solution. ...

Corporate firewall causing issues with AJAX call execution

Currently, I am utilizing jQuery's $.ajax() method to retrieve approximately 26KB of JSONP data. All major browsers including FF, Chrome, IE, and Safari are successfully returning the data from various locations such as work, home, and mobile phone w ...

Using Ajax and PHP to store multiple checkbox selections into the database

I currently have 32 checkboxes on my page that I need to track the checked status for. In my JavaScript, I am looping through each checkbox and assigning a value of '1' for checked and '0' for unchecked. // Example for one checkbox if ...

Display a specific section of an image as the background in a div, with the image scaled and positioned perfectly

Utilizing a 1900 x 1080 image within a div as the background <!DOCTYPE html> <html> <head> <title></title> <meta charset="utf-8" /> <style> html,body { height:100%; } #imageHolder{ ...

Understanding and aggregating data from JSON files

I am in possession of a group of json values outlined below {"labels":[ "time", "softirq", "user", "system", "nice", "iowait" ], "data":[ [ 1490088352, 0, 14.64646, 3.53535, 0, 1.0101 ], [ 1490088351, 0, 27.77778, 3.0303, 0, 0 ], [ 1490088350, 0.49751, 12 ...

Displaying information on a chartJS by connecting to an API using axios in VueJS

Struggling with inputting data into a ChartJS line-chart instance. The chart only displays one point with the right data but an incorrect label (named 'label'): Check out the plot image The odd thing is, the extracted arrays appear to be accura ...

Revise the if statement by using variables

Here is a function that already exists in a theme: function WShare( selector ) { var $this = $( selector ), $parent = $this.parent(); var opt = { url: window.location, text: document.title, }; if ( window.selectedText ) { ...

JavaScript code not functioning on WordPress website (no impact)

I've encountered a strange problem. Here is the code snippet: (function($){ $("#maps1").hover( function(){$("#kontakt_os_1").hide();} ); $("#maps2").hover( function(){$("#kontakt_os_2").hide();} ); $("#maps3").hover( ...

Implementing a dynamic module or dependency addition using a webpack plugin: A comprehensive guide

I'm feeling a bit frustrated because what I am trying to accomplish doesn't seem too difficult, but the documentation for webpack is so disorganized that it's eating up a lot of my time. Can someone please explain how I can inject a "dynami ...

Tips for invoking an asynchronous function within an if condition?

When trying to maintain variables in the background.js of a Chrome extension, I encountered difficulties that require me to reinitialize some global variables. Here is the code snippet (view fiddle) I am using to demonstrate the issue: var temp = null; ...