Last active
July 17, 2017 20:28
-
-
Save MatthewJDavis/3bdbe9fa8fe4a3657308d0799a92f57a to your computer and use it in GitHub Desktop.
update ami id in cloudformation
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
# Get latest Amazon Windows Core AMI and update the ami id in the specified file. | |
# Needs the AWSPowerShell module installed and credentials configured. | |
Import-Module -Name AWSPowerShell | |
$windowsName = 'WINDOWS_2016_Core' | |
$region = 'eu-west-2' | |
$cfFileLocation = 'c:\cloudfromation\win-servers\ec2.yml' | |
#Get the latest AMI ID | |
$imageId = (Get-EC2ImageByName -Name $windowsName -Region $region).ImageId | |
# Get the existing AMI ID from the cloudformation yaml file | |
$existingImageid = (Select-String -Path $cfFileLocation -Pattern "ami-[0-9a-f]{8}" -CaseSensitive).Matches.Value | |
# Update the AMI ID | |
(Get-Content -Path $cfFileLocation).Replace($existingImageid, $imageId) | Set-Content -Path $cfFileLocation -Force |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment