Created
November 18, 2022 05:49
-
-
Save joshuaquek/18a3c0b42da28f750c36a1283ae4bccc to your computer and use it in GitHub Desktop.
Search & Stream Delete all Deployment Script - Deletes all deployment in case the CTQ bash script somehow fails
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
Description: Deletes all deployment in case the CTQ bash script somehow fails |
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
// Run this on NodeJS | |
const axios = require('axios') | |
async function deleteSearchAndStreamDeployments () { | |
const API_KEY = 'YOUR ELASTIC CLOUD API KEY GOES HERE' | |
let deployments = [] | |
try { | |
// Get all deployments from the Elastic Cloud Account | |
const response = await axios({ | |
method: 'GET', | |
url: 'https://api.elastic-cloud.com/api/v1/deployments', | |
headers: { Authorization: `ApiKey ${API_KEY}` }, | |
data: {} | |
}) | |
deployments = response.data.deployments | |
console.log('>>> deployments', deployments) | |
} catch (error) { | |
console.log(error.data) | |
} | |
for (const deployment of deployments) { | |
if (deployment.name.includes('capture-the-query')) { | |
const deploymentId = deployment.id | |
try { | |
// Wipe all deployments with "capture-the-query" in the name | |
const response = await axios({ | |
method: 'POST', | |
url: `https://api.elastic-cloud.com/api/v1/deployments/${deploymentId}/_shutdown`, | |
headers: { Authorization: `ApiKey ${API_KEY}` }, | |
data: {} | |
}) | |
console.log('>>> Response: ', response.data) | |
} catch (error) { | |
console.log(error.data) | |
} | |
// Done, script will exit | |
} | |
} | |
} | |
deleteSearchAndStreamDeployments() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment