Created
January 10, 2018 05:44
-
-
Save reecestart/11c25565b0cee825056cdef06516c9f7 to your computer and use it in GitHub Desktop.
Programmatically get the # of virtual cores for an EC2 instance type to figure out licensing costs
This file contains hidden or 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
# Programmatically get the # of virtual cores for an EC2 instance type to figure out licensing costs | |
# https://aws.amazon.com/ec2/virtualcores/ | |
$Region = 'us-east-1' | |
$ServiceCode = 'AmazonEC2' | |
$Products = Get-plsproduct -ServiceCode $ServiceCode -Filter @{Type="TERM_MATCH";Field="productFamily";Value="Compute Instance"},@{Type="TERM_MATCH";Field="location";Value="Asia Pacific (Sydney)"} -Region $Region | |
$VirtualCoresByAmazonEC2InstanceType = @() | |
foreach ($Product in $Products) | |
{ | |
$myobj = "" | Select "EC2InstanceType","VirtualCoreCount" | |
$Attributes = $Product.Split(",") | |
foreach ($Attribute in $Attributes) | |
{ | |
if ($Attribute -like '*vcpu*') | |
{ | |
$Attribute = $Attribute -replace ".*`":`"" | |
$Attribute = $Attribute.Substring(0,$Attribute.Length-1) | |
$myobj.VirtualCoreCount = $Attribute | |
} | |
elseif ($Attribute -like '*instanceType*') | |
{ | |
$Attribute = $Attribute -replace ".*`":`"" | |
$Attribute = $Attribute.Substring(0,$Attribute.Length-1) | |
$myobj.EC2InstanceType = $Attribute | |
} | |
} | |
if ($VirtualCoresByAmazonEC2InstanceType.EC2InstanceType -like $myobj.EC2InstanceType) | |
{ | |
} | |
else | |
{ | |
$VirtualCoresByAmazonEC2InstanceType += $myobj | |
} | |
$myobj = $null | |
} | |
$VirtualCoresByAmazonEC2InstanceType | Sort-Object -Property EC2InstanceType | Format-Table |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment