Created
September 9, 2024 11:31
-
-
Save fgilio/f86656ac43e4fbb0dff14f4a2bd7d9c7 to your computer and use it in GitHub Desktop.
Bulk delete AWS DynamoDB items from AWS console
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Define a function that performs the desired actions | |
function executeActions() { | |
console.log("Executing actions..."); | |
document.querySelector('[aria-label="Items selection"] input').click(); | |
document.querySelector('button[id^=awsui-button-dropdown__trigger]').click(); | |
document.querySelector('[data-testid="DELETE_ITEM_BUTTON_ID"]').click(); | |
document.querySelector('[data-testid="submit-form"]').click(); | |
console.log("Actions executed."); | |
} | |
// Function to check if the element contains the number "300" | |
function waitForNumber(selector, number, callback) { | |
console.log(`Waiting for the element '${selector}' to contain the number ${number}...`); | |
const interval = setInterval(function() { | |
const element = document.querySelector(selector); | |
if (element) { | |
console.log(`Element found. Current text: "${element.innerText}"`); | |
if (element.innerText.includes(number)) { | |
console.log(`Number ${number} found. Proceeding with actions...`); | |
clearInterval(interval); // Stop checking when the condition is met | |
callback(); // Proceed to execute the actions | |
} else { | |
console.log(`Number ${number} not found yet. Waiting...`); | |
} | |
} else { | |
console.log(`Element '${selector}' not found. Retrying...`); | |
} | |
}, 500); // Check every 500ms | |
} | |
// Function to loop the execution 10 times, waiting for the specific condition each time | |
function loopActions(times) { | |
let counter = 0; | |
function nextIteration() { | |
if (counter < times) { | |
console.log(`Starting iteration ${counter + 1} of ${times}`); | |
waitForNumber('[data-analytics="ResultsTable"] [class^=awsui_header-controls] h2[class^=awsui_heading] [class^=awsui_counter]', "300", function() { | |
executeActions(); // Execute the action when the condition is met | |
counter++; // Increment the counter | |
nextIteration(); // Move to the next iteration | |
}); | |
} else { | |
console.log("All iterations completed."); | |
} | |
} | |
nextIteration(); // Start the loop | |
} | |
// Start the loop with 10 repetitions | |
loopActions(10); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment