Created
April 19, 2015 11:30
-
-
Save Sam-Martin/914dde4b9a9438388082 to your computer and use it in GitHub Desktop.
Generate AMI hashtable for cloudformation
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
# Ensure you amend this value to reflect the AMI you're interested in | |
$imageType = "Windows_Server-2012-R2_RTM-English-64Bit-Core" | |
$resultsArchitectureFirst = @{'64'=@();'32'=@()}; | |
$resultsRegionFirst = @{}; | |
# Loop through all regions and find the appropriate image | |
foreach($region in $(Get-AWSRegion).Region){ | |
if(!($image = $(Get-EC2Image -Region $region -Filters $(New-Object Amazon.EC2.Model.Filter -Property @{Name = "name"; Values = "$ImageType*"}) -Owners 801119661308 | select -first 1))){ | |
continue; | |
} | |
# Figure out the architecture of the OS into the format we want | |
if($image.architecture -eq 'x86_64'){ | |
$architecture = '64'; | |
}else{ | |
$architecture = '32'; | |
} | |
$resultsArchitectureFirst.$architecture += new-object PSObject -Property @{ | |
"Region"=$region; | |
"ImageID"=$image.imageID | |
} | |
$resultsRegionFirst.Add($region,@{ | |
$architecture = $image.imageID; | |
}) | |
} | |
$resultsArchitectureFirst | ConvertTo-Json | |
$resultsRegionFirst | ConvertTo-Json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment