Last active
December 3, 2019 22:24
-
-
Save tylerapplebaum/93293e9c83afdd31c3b8be2b07cd0bac to your computer and use it in GitHub Desktop.
Find EC2 instance availability among all public regions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Check for EC2 instance type availability among all public regions | |
#Prerequisites - the most current AWS CLI installation - https://aws.amazon.com/cli/ | |
[CmdletBinding()] | |
param( | |
[Parameter(HelpMessage="Specify the API name of the EC2 instance type to search for. Example: t3a.small")] | |
[ValidateNotNullOrEmpty()]$InstanceType | |
) | |
$RegionsJson = aws ec2 describe-regions | |
$RegionsObj = $RegionsJson | ConvertFrom-Json | |
$RegionsArr = $RegionsObj.Regions.RegionName | |
$InstanceInRegionArr = New-Object System.Collections.ArrayList | |
$InstanceAvailabilities = ForEach ($Region in $RegionsArr) { | |
#location-type can also be "availability-zone" or "availability-zone-id" | |
$InstanceAvailabilityObj = aws ec2 describe-instance-type-offerings --location-type "region" --filters Name="instance-type",Values="$InstanceType" --region $Region | ConvertFrom-Json | Select-Object -ExpandProperty InstanceTypeOfferings | |
[void]$InstanceInRegionArr.Add($InstanceAvailabilityObj) | |
} | |
Write-Output $InstanceInRegionArr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output looks like this: