5

How to get ec2 instance details(like name,id,type,region,volume,platform,ondemand/reserved) with instance price details .

Using aws api in cli and write it as a csv file .

Thanks in advance .

Arya Ray
  • 73
  • 1
  • 7

3 Answers3

5

similar to my answer here: get ec2 pricing programmatically?

you can do something similar to the following:

aws pricing get-products --service-code AmazonEC2 --filters "Type=TERM_MATCH,Field=instanceType,Value=m5.xlarge" "Type=TERM_MATCH,Field=location,Value=US East (N. Virginia)" --region us-east-1 | jq -rc '.PriceList[]' | jq -r '[ .product.attributes.servicecode, .product.attributes.location, .product.attributes.instancesku?, .product.attributes.instanceType, .product.attributes.usagetype, .product.attributes.operatingSystem, .product.attributes.memory, .product.attributes.physicalProcessor, .product.attributes.processorArchitecture, .product.attributes.vcpu, .product.attributes.currentGeneration, .terms.OnDemand[].priceDimensions[].unit, .terms.OnDemand[].priceDimensions[].pricePerUnit.USD, .terms.OnDemand[].priceDimensions[].description] | @csv'
justsomeguy
  • 513
  • 4
  • 11
  • This is great. Note that you'll have to add `--output json` if you use a different default output format. – joshtch Jan 21 '22 at 21:59
2

I recommand you to use ansible with the ec2-inventory to do so.

Ansible will be able to take all thoses informations using request like:

Then you can have the platform like this for example :

ansible -i ec2.py -m debug -a "var=ec2_platform"  all

You'll have to create a script in yaml to take the informations you need and write them in a csv file.

I don't know any easy way to get the exact price of the servers for amazon-ec2, there is a lot argument to take in account, the OS, the disk space, server type, is it reserved or not, etc ...

But I did a good approximation using what I told you above.

Here is the explanation for dynamic inventory with ansible and ec2: http://docs.ansible.com/ansible/intro_dynamic_inventory.html

Hope it helped !

Hanoo
  • 91
  • 6
  • Thanks @Hanoo . But in current scenario I can't able use ansible to fetching those data and for pricing if I am getting only reserved /ondemand price for particular instance then it's fine for me . – Arya Ray Mar 03 '17 at 10:03
2

If your aim is not to automate the prizing of your servers, you can have a one shot from this URL: https://aws.amazon.com/fr/ec2/pricing/on-demand/

You'll need to know : server type (ex: m3.large) Reservation type (reserved or on demand) OS type (linux, windows, RHEL, ...) the hour coverage (it depends if you shutdown your server or not during the night or else ...)

Then you'll have a good approximation of the prize.

If you want to have more details, you'll have to have a look at your network and data activity. And this is not that easy to calculate...

Another approach would be to go in your pricing menu, and look at your facturation to know what you paid for the past month. But this won't work if you want to estimate the prize of a new server.

Hope it helped.

Hanoo
  • 91
  • 6