Skip to content

Instantly share code, notes, and snippets.

@housemeow
Created February 21, 2019 08:51
Show Gist options
  • Save housemeow/6011e19102849a84d9dceadde50c6083 to your computer and use it in GitHub Desktop.
Save housemeow/6011e19102849a84d9dceadde50c6083 to your computer and use it in GitHub Desktop.
Find Cheapest EC2 Instance
// https://aws.amazon.com/tw/ec2/pricing/on-demand/
var $item = $('.button.lb-dropdown-label:eq(0) li:eq(0)'),
clicked = false,
regions = [];
var interval = setInterval(function() {
if ($item.length == 0) {
clearInterval(interval);
console.log('Cheapest', regions.reduce((a, b) => b.price < a.price ? b : a, { price: 1000}));
}
if (!clicked) {
$item.click().click();
clicked = true;
}
var region = $item.data('region');
if ($('.aws-plc-content:eq(0)').find(`div[data-region=${region}] table`).length > 0) {
var row = $.map($(`[data-region="${region}"] tr td:nth-child(6)`), el => ({ price: $(el).text(), ec2: $(el).siblings(':first').text() }))
.map(row => ({ price: row.price.match(/每小時 (\d*\.\d*) USD/)[1], ec2: row.ec2 }))
.map(row => ({ price: parseFloat(row.price), ec2: row.ec2 }))
.reduce((a, b) => b.price < a.price ? b : a, { price: 1000 }),
name = $(`li[data-region="${region}"]:eq(0)`).text();
regions.push({
region,
name,
price: row.price,
ec2: row.ec2,
});
$item = $item.next();
clicked = false;
}
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment