
Show HN: Curl https://ec2.shop - kureikain
https://ec2.shop
======
kureikain
From time to time, I want a quick tool to help me compare EC2 instances price.
[https://ec2instances.info/](https://ec2instances.info/) works great but it's
somewhat slow and didn't have a way to just `curl` from terminal.

So I develop this small tool which you can do thing like

    
    
        curl https://ec2.shop
        curl https://ec2.shop?region=us-west-2&filter=t2,m4

~~~
JimDabell
Are you manually detecting Curl specifically? If I use anything other than
Curl, e.g. HTTPie or wget, I get the HTML page, even if I provide an `Accept:
text/plain` request header. If I use one of those tools and spoof the Curl
user agent string, I get the text/plain response. You should probably just
look at the Accept request header, it’s there specifically so clients can tell
you what kind of response they want.

~~~
kureikain
Great idea.

I just implement it:
[https://github.com/yeo/ec2.shop/commit/ab258aef3ac2ad3d45b26...](https://github.com/yeo/ec2.shop/commit/ab258aef3ac2ad3d45b26d76304476424379a77c)

Now by default it's text mode, so request by http client library or tool like
curl, wget, httppie all get text bersion.

Only when detecting `Accept` contains `html` and user agent is
safari/chrome/firefox etc it send html version.

~~~
karmakaze
There should be no reason to check user agent if already checking `Accept`.
That's usually more for browser quirks or allow/blocking.

------
kissgyorgy
You can do cool things with this very quickly. For example, I always wondered
the price differences between different regions, you can compare two instance
prices quickly:

    
    
        diff -u <(curl -sS "https://ec2.shop?region=eu-central-1" | grep "t3.large" ) <(curl -sS "https://ec2.shop?region=us-east-1" | grep "t3.large")

------
echeese
The prices column is sorted lexicographically, instead of numeric, i.e. 1, 10,
2

~~~
ohashi
They all are

~~~
kureikain
I fixed this sorting issue :-). Give it another try.

------
solatic
Color output seems to be tuned for dark terminal backgrounds. Memory, vCPUs,
and Storage are nearly unreadable on a white background.

~~~
hnlmorg
I've moaned about this with other CLI tools as well. I wish trend of using RGB
values in ANSI escape codes would die because as ugly as the 16*3 colour
fields¹ are, they are at least customisable so people can use palettes that
suite their terminal and eyesight.

You don't get any such opportunity if the developers hard code the colour
values in (and it's worse with a tool like this because you can't even set an
environmental variable to change the tools behaviour)

¹ sixteen colours plus bright and dark variants

~~~
ASVVVAD
Can you link me to a way to use colours that change with the terminal colour
preset? I haven't come across anything like that or maybe didn't pay
attention. It would be really helpful

You said you can't even set an env variable to change them so I assume that
there is an even better way?

~~~
hnlmorg
Wikipedia has a good section on the different methods of describing colour:
[https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit)

I've got some Go code that you can reuse if you want to the escape codes in
Go:
[https://github.com/lmorg/murex/blob/master/utils/ansi/codes....](https://github.com/lmorg/murex/blob/master/utils/ansi/codes.go)

Just bare in mind that any numbers you see in documentation are sent as ASCII
values rather than integers. eg `ESC[31m` (red text) should be sent to the
terminal as

    
    
        []byte{  // http://www.asciitable.com/
            27,  // ESC character code
            91,  // '['
            51,  // '3'
            49,  // '1'
            109, // 'm'
        }
    
    

Though, as you know, most languages will have some syntactic sugar to
translate characters to their ASCII values, eg

    
    
        'm' == 109
        Asc("m") == 109
        ...etc...
    

so at least you don't have to write all those values by hand.

~~~
ASVVVAD
Thanks for the explanation and the snippets ^^

------
shitloadofbooks
I really like this, but the horizontal lines are not helpful at all and just
double the number of lines for no benefit.

You can obviously

    
    
        curl ec2.shop | grep -v ─
    

but I'm not sure I want to do that every time and I'm not exactly sure why,
but when I do that, I can't select the entire row, only a column at a time
(zsh on iTerm 2).

~~~
kureikain
I turn off the color :-). And I must say it much nicer without color. Thank
you.

------
cheeaun
Is this open sourced?

I personally try looking into implementing a curl "interface" to one of my
projects, realised that it actually need to check the user-agent (of curl and
a plethora of curl alternatives) which I find kind of weird...

~~~
kureikain
Hey, yes it's 100% open source.

[https://github.com/yeo/ec2.shop](https://github.com/yeo/ec2.shop)

The reason it check `curl` agent is because it share the same endpoint (root
url) for both of `curl` page and browser version(the one with dropdown, grid
etc)

~~~
cheeaun
I see, thanks!

------
soerface
Neat! The prices are without currency symbols - I guess it's always USD? Or
maybe dependent on the region…? Would be nice if the $ symbol is printed, and
even better if I could see the prices of my european servers in european
currency - maybe add a param to select the currency?

It would be very helpful if you would support the `Accept: application/json`
header. This way, we could use it in combination with jq to do arbitrary
filtering:

    
    
        curl -L -H "Accept: application/json" ec2.shop | jq .

------
YoavR7
Cool! You should probably add http support and not only https. Writing `curl
ec2.shop` is easier than `curl [https://ec2.shop`](https://ec2.shop`)

~~~
saurik
For HTTPS to truly be meaningful we need to stop supporting HTTP as an on-
ramp, to prevent people from just hijacking that initial unencrypted
connection and sending anything they want.

~~~
Znafon
If you MITM and the user agent send an HTTP request for ec2.shop it does not
matter whether the webserver supports HTTP or not, you can send a fake HTTP
response either way.

~~~
hnlmorg
That was the GPs point.

------
baliex
Could you update the `...&filter...` example to wrap the URL in quotes so that
the `&` isn't interpretted by the shell as sending the process to the
background?

~~~
elemenophy
this is an issue of ZSH.

~~~
hnlmorg
That is a POSIX standard and not something specific to zsh

------
nnx
Interesting tool. Would be really useful if it supported Spot prices, which
are even more of a PITA to find using Amazon’s UI.

~~~
kureikain
Yes, it isn't that hard to support Spot prices but the price change too often
so I have to scrape it for every 5 minutes. Right now, I haven't had the
automation to run this yet but it's doable and my pain point too =)

------
kureikain
Wow, thank you for the feedback. I'm going to implement lot of features
suggest in this page.

Since I cannot edit original comment, yes, the site is open source:
[https://github.com/yeo/ec2.shop](https://github.com/yeo/ec2.shop)

------
dxxvi
Can I be sure that the prices from this endpoint are accurate (i.e. if Amzn
changes the prices, this endpoint will reflect that change)? Off-topic: if I
request a spot instance, is there any way (API/cli) to know how much Amzn
charges me every hour for that instance?

~~~
gen220
I've built something like this in the past (I was running a beefy server for
my friends, and wanted them to know how much it was costing us at an hourly
rate, before they ran it for 3 weeks straight).

It's definitely possible and not very challenging, but the API Documentation
for prices was pretty weak when I built it (a year or two ago, written in Go
if it makes a difference). The google cloud prices API was similarly gross. It
was kinda fun, but I wouldn't enjoy maintaining that code. In reality, it
turns out that $/hour isn't a super straightforward metric (there are many
dimensions that go into it), so it's not super straightforward to query.

------
zkirill
Super! It would be great to see price per month as well.

------
css
Very neat. Anyone know why

    
    
        curl -s https://ec2.shop | grep 't2'
    

would work, but

    
    
        curl -s https://ec2.shop | grep 'm4'
    

does not? Both commands work if I write the curl result to a file, but when I
pipe from curl, the pattern `m4` matches all instances of the number 4.

~~~
kureikain
Thank you, this is a bug.

The color code for blue is `"\033[34m` so it always match m4 for anything :(.

Just push a fix by disabling color as suggestion in here as well

~~~
css
Ah, got it, thanks for the clarity.

------
xhrpost
Neat, didn't realize how much the options for ec2 have grown over time. Can
those instances with 100Gbps networking actually push that to upstream transit
(ie. the Internet)? Or is that mostly for internal network communication
between instances and other AWS services?

------
nine_k
The examples miss the opening quote before the URLs.

Illustration: [http://dmitry.cheryasov.info/random/missing-quote-
mark.jpg](http://dmitry.cheryasov.info/random/missing-quote-mark.jpg)

------
ryanmccullagh
Nice list. Recently, I loaded all the prices into an Excel document to make
things easier for projecting costs and determining prices. I always use the
following formula for estimating monthly costs on Amezmo.

$Hourly * 750

750 being the number of hours in 1 month.

------
afshinmeh
Nice! thanks for using [https://gridjs.io](https://gridjs.io) :)

------
m00dy
now curl is the new black ? :) This is not my first time that I see curl based
services.

------
alexellisuk
Could you have it retain the sort order when changing region?

------
kolinkorr839
Is there a way to show the output in json format?

~~~
mike-cardwell
Would be nice if both of these work (they don't):

curl [https://ec2.shop](https://ec2.shop) -H 'Accept: application/json'

curl [https://ec2.shop?json](https://ec2.shop?json)

~~~
kureikain
It should work that way now :-). Thanks for suggestion.

------
JosephRedfern
Very hand. Can you add sorting?

~~~
hnlmorg
...or remove the pretty line glyphs so this tool can be used in a normal CLI
pipeline (eg `sort`)

------
kstrauser
Bravo. This is really lovely!

------
vmception
I like this trend

