AWS Cloud Operations & Migrations Blog

Query for the Latest Windows AMI Using Systems Manager Parameter Store

AWS has introduced a simpler way for you to query for the latest Windows Amazon Machine Image (AMI). You can now use Amazon EC2 Systems Manager Parameter Store. Prior to this release, finding the latest regional ImageID for an Amazon-provided AMI involved a three-step process. First, use an API call to search the list of available public AMIs. Second, filter the results by a given partial string name. Third, sort the matches by CreationDate property and select the newest ImageID.

Now, the latest version of a Windows regional ImageID can be returned from a simple Parameter Store query. Each Windows AMI now has its own Parameter Store namespace that is public and describable. Upon querying, an AMI namespace returns only its regional ImageID value.

The namespace is made up of two parts:

  1. Parameter Store Prefix (tree): /aws/service/ami-windows-latest/
  2. AMI name alias: Windows_Server-2016-English-Full-Base

You can determine a Windows AMI alias by taking the full AMI name property of a Windows public AMI and removing the date-based version identifier at the end.  A list of these AMI name properties can be seen by running one for the following EC2 queries.

Using PowerShell

- Get-EC2ImageByName -Name Windows_Server* | Sort-Object CreationDate | Select-Object Name

Using AWS CLI

- aws ec2 describe-images --owners amazon --filters "Name=name,Values=Windows_Server*" --query 'sort_by(Images, &CreationDate)[].Name'

For example, Windows_Server-2016-English-Full-Base-2017.10.13 without the date-based version becomes Windows_Server-2016-English-Full-Base. When you add the public Parameter Store prefix namespace to the AMI alias you have the Parameter Store name of “/aws/service/ami-windows-latest/Windows_Server-2016-English-Full-Base”

Each unique AMI namespace always remains the same. You no longer need to pattern match on name filters, and you no longer need to sort through CreationDate AMI properties. As Windows AMIs are patched and new versions are released to the public, AWS will update the Parameter Store value with the latest ImageID for each AMI namespace in all supported Regions.

Querying for the latest AMI using public Parameters

Once you have your target namespace, your query can be created to retrieve the latest AWS Windows ImageID. Each region has an exact replica namespace containing its region specific ImageID value.

Using PowerShell

Get-SSMParameter -Name /aws/service/ami-windows-latest/Windows_Server-2016-English-Full-Base -region us-east-1

Using AWS CLI

aws ssm get-parameters --names /aws/service/ami-windows-latest/Windows_Server-2016-English-Full-Base --region us-east-1

Always launch new instances with the latest ImageID

After you have created the query, you can embed the command as a command substitution into your new instance launches.

Using PowerShell

New-EC2Instance -ImageId ((Get-SSMParameterValue -Name /aws/service/ami-windows-latest/Windows_Server-2016-English-Full-Base).Parameters[0].Value) -InstanceType m4.large -AssociatePublicIp $true -SubnetId subnet-abcd1234

Using AWS CLI

aws ec2 run-instances --image-id $(aws ssm get-parameters --names /aws/service/ami-windows-latest/Windows_Server-2016-English-Full-Base  --query 'Parameters[0].[Value]' --output text) --count 1 --instance-type m4.large --subnet-id subnet-abcd1234

This new instance launch always results in the latest publicly available Windows AMI for Windows_Server-2016-English-Full-Base. Similar embedding can be used in a number of automation process, docs, and coding languages.

Display a complete list of all available public Parameter Windows AMIs

You can also query for the complete list of AWS Windows Parameter Store namespaces available.

Using PowerShell

Get-SSMParametersByPath -Path "/aws/service/ami-windows-latest" -region us-east-1

Using AWS CLI

aws ssm get-parameters-by-path --path "/aws/service/ami-windows-latest" --region us-east-1

Partial list of public Parameter AWS Windows AMIs

/aws/service/ami-windows-latest/Windows_Server-2016-Turkish-Full-Base
/aws/service/ami-windows-latest/Windows_Server-2016-Swedish-Full-Base
/aws/service/ami-windows-latest/Windows_Server-2016-Spanish-Full-Base
/aws/service/ami-windows-latest/Windows_Server-2016-Russian-Full-Base
/aws/service/ami-windows-latest/Windows_Server-2016-Portuguese_Portugal-Full-Base
/aws/service/ami-windows-latest/Windows_Server-2016-Portuguese_Brazil-Full-Base
/aws/service/ami-windows-latest/Windows_Server-2016-Polish-Full-Base
/aws/service/ami-windows-latest/Windows_Server-2016-Korean-Full-SQL_2016_SP1_Standard
/aws/service/ami-windows-latest/Windows_Server-2016-Korean-Full-Base
/aws/service/ami-windows-latest/Windows_Server-2016-Japanese-Full-SQL_2016_SP1_Web
/aws/service/ami-windows-latest/Windows_Server-2016-Japanese-Full-SQL_2016_SP1_Standard
/aws/service/ami-windows-latest/Windows_Server-2016-Japanese-Full-SQL_2016_SP1_Express
/aws/service/ami-windows-latest/Windows_Server-2016-Japanese-Full-SQL_2016_SP1_Enterprise
/aws/service/ami-windows-latest/Windows_Server-2016-Japanese-Full-Base
/aws/service/ami-windows-latest/Windows_Server-2016-Italian-Full-Base
/aws/service/ami-windows-latest/Windows_Server-2016-Hungarian-Full-Base
/aws/service/ami-windows-latest/Windows_Server-2016-German-Full-Base
/aws/service/ami-windows-latest/Windows_Server-2016-French-Full-Base
/aws/service/ami-windows-latest/Windows_Server-2016-English-Nano-Base
/aws/service/ami-windows-latest/Windows_Server-2016-English-Full-SQL_2017_Web
/aws/service/ami-windows-latest/Windows_Server-2016-English-Full-SQL_2017_Standard
/aws/service/ami-windows-latest/Windows_Server-2016-English-Full-SQL_2017_Express
/aws/service/ami-windows-latest/Windows_Server-2016-English-Full-SQL_2017_Enterprise 

About the Author

Steven Armentrout is a Systems Engineer on the Amazon EC2 Windows team and has over a decade of enterprise experience in the public and private sectors as System Administrator, Systems Engineer and Network Engineer. The resident expert on Windows Amazon Machine Images. The seeker of simplicity and ease of use. Living the dream and making a mark on the future of the cloud.