Search code examples
amazon-web-serviceskubernetestestautomationfx

Spot Instance "frequency of interruption" ratio get as scheduled


AWS announces "frequency of interruption" on the page without API in here: https://aws.amazon.com/ec2/spot/instance-advisor/

I need to get all types(255 pieces) on Virginia in a scheduled way. How can I do that?


Solution

  • I solved it by crawling the page with selenium and Python. You can run the following script in docker, it will create aws-spot-instance.txt the pwd.

    You can change the region, it is region = 'US East (N. Virginia)' in the script.

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.chrome.options import Options
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    options = Options()
    options.add_argument("--headless") # Runs Chrome in headless mode.
    options.add_argument('--no-sandbox') # # Bypass OS security model
    options.add_argument('start-maximized')
    options.add_argument('disable-infobars')
    options.add_argument("--disable-extensions")
    options.add_argument('--disable-gpu')
    
    region = 'US East (N. Virginia)'
    
    driver = webdriver.Chrome(chrome_options=options)
    driver.get("https://aws.amazon.com/ec2/spot/instance-advisor")
    element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, ".dropdown-container.aws-dropdown-region.dropdown-built")))
    element.click()
    driver.find_element_by_xpath("//span[text()='%s']" %region).click()
    driver.find_element_by_css_selector(".aws-spot-advisor-button-expand.button").click()
    
    table_data = driver.find_element_by_css_selector(".table.table-striped").text
    fw = open('aws-spot-instance.txt', "w")
    fw.write(table_data)
    fw.close()
    

    save this script a aws.py and run the following command:

    docker pull gunesmes/python-selenium-behave-page-object-docker
    docker run --rm --name aws -v $PWD:/project gunesmes/python-selenium-behave-page-object-docker bash -c "python3 aws.py"
    

    enter image description here