AWS Developer Blog

Getting the Latest Windows AMIs

by Steve Roberts | on | in .NET | Permalink | Comments |  Share

More and more developers are launching the AWS base Windows AMIs and configuring them during startup. You can do this either by adding a PowerShell script to the user data field or by using an AWS CloudFormation template to configure it. We are constantly updating these base AMIs to include the latest patches. The SDK contains the ImageUtilities class, which you can find in the Amazon.EC2.Util namespace. This class is useful for finding the latest AMIs using named service pack/’RTM’ independent constants. For example, the following code will find the latest Windows 2012 with SQL Server Express AMI:

Image image = ImageUtilities.FindImage(ec2Client, ImageUtilities.WINDOWS_2012_SQL_SERVER_EXPRESS_2012);

Using the version-independent constants means that you do not need to rebuild your code when the Amazon EC2 team revises the published AMIs. The new EC2 sample that was recently added to Visual Studio under ”Compute and Networking” demonstrates how to use the ImageUtilities class and execute a PowerShell script at startup. Using AWS Tools for PowerShell you can also use the Get-EC2ImageByName cmdlet:

"WINDOWS_2012_SQL_SERVER_EXPRESS_2012" | Get-EC2ImageByName | New-EC2Instance ...

The cmdlet accepts either the logical, service pack/RTM-independent names or specific name patterns. The current names can be seen by invoking the cmdlet with no parameters. Just like using the SDK, if you script using logical names to address the AMIs, your script does not need to be updated when Amazon EC2 revises the current AMIs as new service packs are released!