Do you need the list of available instance types in a particular AWS Region?

I did today. Well, someone else did but I thought I could help them with the issue. So I cobbled something together today and it seems to be working fine.

Generally, the idea is to use Get-PLSProduct cmdlet. What it does is “Calls the AWS Price List Service GetProducts API operation”. Then we can parse it and see which instances can be launched in a particular AWS region. Nice, right? 🙂

We should probably do some filtering for the list of products, otherwise it would both take too long and return unnecessary information + duplicates.

Here you can see that the calling region for the cmdlet is hard-coded to us-east-1. This is the only region where the Price List Service can be contacted it, keep it in mind 🙂

So, what do we have filter-wise, and why?

Location = TargetRegion. This is pretty much self-explanatory. Wanted region goes here 🙂
preInstalledSW = NA. We can eliminate a huge number of returned results and significantly speed up the query by eliminating everything that’s not a plain product.
tenancy = Shared. This will make sure we don’t get dedicated instances and hosts in results. Shared images will cover everything. Speeding things up.
OperatingSystem = Linux. We could have used Windows as well. I didn’t, you can. Deduplication, again, improves speed.

Funny thing with the AWS Price List Service is that it likes calling some regions in its own way, slightly different than what Get-AWSRegion would return. Examples would be “EU West (Ireland)” and “EU Central (Frankfurt)” vs “EU (Ireland)” and “EU (Frankfurt)”. It’s not just EU, N. Virginia also differs 🙂

Once our query is formed, sent and captured, we will need to parse it. For each of the instance types we’ll need to peek into $Product.product.attributes.instanceType to see the instance type.

As you can see, if it matches what we need we add it to the list. Then display everything in it using only unique entries – Write-Output $InstanceTypes | Sort-Object -Unique

That’s all there is to it 🙂

Have fun!

Get the code (and any future updates) from GitHub: https://github.com/PowerSix/MyPowerShellSpace

As usual, if the script is updated, this blog post won’t be.
Always check the GitHub repo for the latest version.

Some screenshots to demonstrate the usage. Full code below.

Leave a Comment