I’m trying to write a python script using boto3 in order to get hourly prices of an instance, given the instance ID. I should remark that I’m not speaking about costs that you can get from cost explorer, I’m speaking about nominal hourly price, for example for an ‘ec2’ instance.
I’ve already found some examples using “boto3.client(‘pricing’,…)” and a bunch of parameters and filters as in:
https://www.saisci.com/aws/how-to-get-the-on-demand-price-of-ec2-instances-using-boto3-and-python/
which also requires region code to region name conversion.
I would like not to have to specify every instance detail and parameter for that query.
Can anybody help me to find a way to get that info just having the ec2 instance ID?
Thanks in advance.
Advertisement
Answer
You have to pass all that information. If you want to write a script that takes an instance ID and returns the hourly price, then you would first need to use the instance ID to lookup the instance details, and then pass those details to the pricing query.