Did you know AWS Systems Manager (SSM) Parameter Store offers a convenient way to find the latest Amazon Machine Image (AMI) IDs? Using the latest AMI when launching Amazon EC2 instances can be crucial for security and performance. We will cover
Let’s walk through both AWS CLI and PowerShell methods to use public SSM Parameters to find the latest AMI for Windows Server 2016 and launch a Windows EC2 instance with it.
Using SSM Parameters with AWS CLI Link to heading
AWS CLI (Command Line Interface) is a powerful tool that allows you to interact with AWS services. To launch an EC2 Windows instance with the latest Windows Server 2016 AMI using AWS CLI, follow these steps:
- Query the Latest Windows AMI: Use the SSM Parameter Store to retrieve the latest AMI ID.
aws ssm get-parameters --names /aws/service/ami-windows-latest/Windows_Server-2016-English-Full-Base --region us-west-2
- Launch an EC2 Instance: Embed the command to retrieve the latest AMI ID in your instance launch command.
aws ec2 run-instances --image-id resolve:ssm:/aws/service/ami-windows-latest/Windows_Server-2016-English-Full-Base --count 1 --instance-type t2.medium --region us-west-2
This method ensures that your new instance uses the most current Windows Server 2016 AMI available.
Using SSM Parameters with PowerShell Link to heading
PowerShell provides an alternative scriptable interface to manage AWS services. Here’s how to launch an EC2 instance with the latest Windows AMI using PowerShell:
- Retrieve the Latest Windows AMI:
Use the
Get-SSMParameter
cmdlet to get the latest AMI ID.
Get-SSMParameter -Name /aws/service/ami-windows-latest/Windows_Server-2016-English-Full-Base -region us-west-2
- Launch the EC2 Instance:
Use the
New-EC2Instance
cmdlet, incorporating the latest AMI ID.
New-EC2Instance -ImageId ((Get-SSMParameterValue -Name /aws/service/ami-windows-latest/Windows_Server-2016-English-Full-Base).Parameters[0].Value) -InstanceType t2.medium -AssociatePublicIp $true -region us-west-2
Other operating systems have their own parameter paths. For example, Amazon Linux 2 can be found by using /aws/service/ami-amazon-linux-latest/
, see the Finding public parameters on the AWS Docs for more information.
You can see that using SSM Parameters to launch EC2 instances with the latest AMIs is an efficient way to ensure your instances are up-to-date. Whether you prefer AWS CLI or PowerShell, both methods provide a reliable and automated approach to instance deployment with the latest Windows AMIs.
Pro PowerShell for Amazon Web Services:
If you found this tip helpful and are looking for more content on using PowerShell with AWS, you might find my book, “Pro PowerShell for Amazon Web Services”, helpful.
Emmanuel Tsouris is a Systems Development Manager working in the cloud, with extensive experience in cloud platforms, enterprise management, and automation. In his spare time, he enjoys hiking, biking, cooking, photography, and writing. For more insights and tips, visit emmanueltsouris.com.