Skip to content

Instantly share code, notes, and snippets.

@joshuaquek
Created November 18, 2022 05:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshuaquek/18a3c0b42da28f750c36a1283ae4bccc to your computer and use it in GitHub Desktop.
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
Description: Deletes all deployment in case the CTQ bash script somehow fails
// 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