erans / ec2instancespricing Goto Github PK
View Code? Open in Web Editor NEWQuick and dirty Python API and CLI to get EC2 instance pricing for On-Demand and Reserved Instances
License: Other
Quick and dirty Python API and CLI to get EC2 instance pricing for On-Demand and Reserved Instances
License: Other
I tried to pull reserved instance information, but the region eu-central-1 for example is missing. We even have more eu- regions. but it seems to only pull eu-west-1.
I would like to how to run this script is there any specific parameter args I need to run the script right now im just using python ec2instancespricing.py. However I'm getting this error when running the scripts
Traceback (most recent call last):
File "ec2instancespricing.py", line 854, in
data, _ = _get_data(args)
File "ec2instancespricing.py", line 801, in _get_data
data = merge_instances(data, get_ec2_spot_instances_prices(args.filter_region, args.filter_type, args.filter_type_pattern, args.filter_os_type))
File "ec2instancespricing.py", line 739, in get_ec2_spot_instances_prices
result = get_ec2_instances_prices(urls, "spot", filter_region, filter_instance_type, filter_instance_type_pattern, filter_os_type, use_cache, cache_class)
File "ec2instancespricing.py", line 544, in get_ec2_instances_prices
region_name = JSON_NAME_TO_EC2_REGIONS_API[r["region"]]
KeyError: 'us-west-2-lax-1a'
Example t1.micro us-east ondemand is missing.
Hi,
Thanks a lot for writing a very useful tool!
As the title says, the url http://aws.amazon.com/ec2/pricing/json/linux-od.json now redirects to https://a0.awsstatic.com/pricing/1/deprecated/ec2/linux-od.json ?
On the ec2 pricing page, it uses something like for ec2 pricing data:
https://a0.awsstatic.com/pricing/1.0.19/ec2/linux-od.min.js
Maybe it's time to update to the new formats of pricing data for ec2?
Thanks a lot,
Heling
Thanks for your efforts on this project.
There is some evidence that Amazon's json pages may have changed format today. Have you had experience with this?
Test program (foo.py):
#!/usr/bin/env python
from ec2instancespricing import ec2instancespricing
prices = ec2instancespricing.get_ec2_ondemand_instances_prices()
Results:
$ python foo.py
Traceback (most recent call last):
File "foo.py", line 5, in
prices = ec2instancespricing.get_ec2_ondemand_instances_prices()
File ".../libs/ec2instancespricing/ec2instancespricing.py", line 456, in get_ec2_ondemand_instances_prices
instance_size = INSTANCE_SIZE_MAPPING[s["size"]]
KeyError: 'm1.small'
Just picking nits, but in addition to argparse and prettytables, I had to run easy_install demjson
before running the python script.
Need to add Canada and London
"ca-central-1": "ca-central-1",
"eu-west-2": "eu-west-2",
Missing an n here!
get_ec2_ondemand_instances_prices - to get the pricing of On-Demand instances
get_ec2_reserved_instances_prices - to get the pricing of reserved instances (in all utilization levels)
get_ec2_spot_instances_prices - to get the pricing of spot instances
I'm looking for the prices for ondemand
, us-east-1
, linux
, m3.2xlarge
. In the page, it says that the price is $0.560:
But when I run the script like this:
./ec2instancespricing.py --type ondemand --filter-region us-east-1 --filter-type 'm3.2xlarge' --filter-os-type 'linux' --format json
The output is:
{"regions": [{"region": "us-east-1", "instanceTypes": [{"os": "linux", "price": 0.9, "type": "m3.2xlarge"}]}], "config": {"currency": "USD", "unit": "perhr"}}
I think the problem is that the API may be deprecated. If you make a request to http://aws.amazon.com/ec2/pricing/pricing-on-demand-instances.json, you will see that it redirects to a deprecated API.
Hi, I am trying to run this code using python but it is not running? Can you please tell me how I can run this? Thanks.
ImportError Traceback (most recent call last)
in ()
----> 1 import ec2instancespricing
/usr/local/lib/python2.7/dist-packages/ec2instancespricing/init.py in ()
----> 1 from ec2instancespricing.ec2instancespricing import get_prices
ImportError: No module named ec2instancespricing
I have installed pretty table but it is showing this error.
ImportError: No module named 'prettytable'
It looks like the "g2.2xlarge" instance type is missing.
Hello
I am getting an error:
KeyError: u'ap-east-1'
when trying to run the CLI
Traceback (most recent call last):
File "Library/Python/2.7/bin/ec2instancespricing.py", line 4, in
import('pkg_resources').run_script('ec2instancespricing==0.1', 'ec2instancespricing.py')
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/init.py", line 742, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/init.py", line 1674, in run_script
exec(script_code, namespace, namespace)
File "/Users/jamesgardiner/Library/Python/2.7/lib/python/site-packages/ec2instancespricing-0.1-py2.7.egg/EGG-INFO/scripts/ec2instancespricing.py", line 852, in
File "/Users/jamesgardiner/Library/Python/2.7/lib/python/site-packages/ec2instancespricing-0.1-py2.7.egg/EGG-INFO/scripts/ec2instancespricing.py", line 799, in _get_data
File "/Users/jamesgardiner/Library/Python/2.7/lib/python/site-packages/ec2instancespricing-0.1-py2.7.egg/EGG-INFO/scripts/ec2instancespricing.py", line 737, in get_ec2_spot_instances_prices
File "/Users/jamesgardiner/Library/Python/2.7/lib/python/site-packages/ec2instancespricing-0.1-py2.7.egg/EGG-INFO/scripts/ec2instancespricing.py", line 542, in get_ec2_instances_prices
Traceback:
File "./ec2instancespricing/ec2instancespricing.py", line 510, in get_ec2_instances_prices
region_name = JSON_NAME_TO_EC2_REGIONS_API[r["region"]]
KeyError: u'ap-south-1'
Fixed by adding new entity to map
If you're willing to pull in botocore,
import botocore.session
sess = botocore.session.Session()
available_types = sess.get_service_model('ec2').shape_for('InstanceType').enum
generates the instance type list at runtime; wouldn't be hard to work that in instead.
How do you feel about that, philosophically?
iam already install pretty table but my terminal show this error:cannot import name 'PrettyTable' from partially initialized module 'prettytable' (most likely due to a circular import)
Originally posted by @2masa in #49 (comment)
If i want to print_r i get everytime
Undefined index: m1.small
I'm runnning the script like this:
./ec2instancespricing.py --type ondemand --filter-region us-east-1 --filter-type 'm3.2xlarge' --filter-os-type 'linux' --format json
And I'm getting this error:
Traceback (most recent call last):
File "./ec2instancespricing.py", line 527, in <module>
print json.dumps(data)
NameError: name 'json' is not defined
The problem is that, when the json module was changed, it was forgotten to change this line.
With the new reservation pricing scheme they've updated it all again
haven't found the json files yet but here are the .js versions
https://a0.awsstatic.com/pricing/1/ec2/linux-od.min.js
https://a0.awsstatic.com/pricing/1/ec2/previous-generation/ri-v2/linux-unix-shared.min.js
you need to pull off the callback( ... ); bit - however still not parsing as son
It would be awesome if this were in pip.
Hynek wrote a nice guide.
If I had some time, I'd do this in my fork.
Thanks for creating this.
Hi,
It would be great if you could specify what license this code is released under. MIT, BSD or Apache would be ideal. Otherwise no one is able to legally use or extend this code!
Thanks
There's a new API that's available for some (but not ALL) services: http://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/price-changes.html. This script should slowly migrate to that set of APIs
Here's a module that's already using it: https://github.com/lashex/pyutu
We can't switch to that yet since this module also covers services that aren't available from the new API.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.