Skip to content

Instantly share code, notes, and snippets.

@tylerapplebaum
Last active December 3, 2019 22:24
Show Gist options
  • Save tylerapplebaum/93293e9c83afdd31c3b8be2b07cd0bac to your computer and use it in GitHub Desktop.
Save tylerapplebaum/93293e9c83afdd31c3b8be2b07cd0bac to your computer and use it in GitHub Desktop.
Find EC2 instance availability among all public regions
#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
@tylerapplebaum
Copy link
Author

Output looks like this:

PS C:\Users\username> .\Find-EC2InstanceAvailabilityByRegion.ps1 -InstanceType t3a.small

InstanceType LocationType Location
------------ ------------ --------
t3a.small    region       ap-south-1
t3a.small    region       eu-west-3
t3a.small    region       eu-west-2
t3a.small    region       eu-west-1
t3a.small    region       ap-northeast-2
t3a.small    region       ap-northeast-1
t3a.small    region       sa-east-1
t3a.small    region       ca-central-1
t3a.small    region       ap-southeast-1
t3a.small    region       ap-southeast-2
t3a.small    region       eu-central-1
t3a.small    region       us-east-1
t3a.small    region       us-east-2
t3a.small    region       us-west-1
t3a.small    region       us-west-2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment