<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>EC2 · Emmanuel Tsouris</title>
    <link>https://www.emmanueltsouris.com/tags/ec2/</link>
    <description>Places, culture, memory, and how ordinary things work. Why is it like that?</description>
    <language>en-us</language>
    <managingEditor>Emmanuel Tsouris</managingEditor>
    <webMaster>Emmanuel Tsouris</webMaster>
    <copyright>© 2026 Emmanuel Tsouris</copyright><lastBuildDate>Sun, 03 Dec 2023 05:30:03 +0000</lastBuildDate>
    <atom:link href="https://www.emmanueltsouris.com/tags/ec2/index.xml" rel="self" type="application/rss+xml"/>
    <item>
      <title>How to Launch EC2 Windows Instances with the Latest AMI Using AWS CLI and PowerShell</title>
      <link>https://www.emmanueltsouris.com/posts/launching-ec2-windows-instances-latest-ami-aws-cli-powershell/</link>
      <pubDate>Sun, 03 Dec 2023 05:30:03 +0000</pubDate>
      <guid isPermaLink="true">https://www.emmanueltsouris.com/posts/launching-ec2-windows-instances-latest-ami-aws-cli-powershell/</guid>
      <dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Emmanuel Tsouris</dc:creator>
      <description>Let&#39;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.</description>
      
      <content:encoded><![CDATA[<p>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</p>
<p>Let&rsquo;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.</p>
<h2 id="using-ssm-parameters-with-aws-cli">Using SSM Parameters with AWS CLI<a class="heading-anchor" href="#using-ssm-parameters-with-aws-cli" aria-label="Link to this section"><svg class="icon" viewBox="0 0 24 24" aria-hidden="true"><path d="M10 14a4.5 4.5 0 0 0 6.6.4l2.5-2.5a4.6 4.6 0 0 0-6.5-6.5l-1.4 1.4"/><path d="M14 10a4.5 4.5 0 0 0-6.6-.4L4.9 12a4.6 4.6 0 0 0 6.5 6.5l1.4-1.4"/></svg></a></h2>
<p>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:</p>
<ol>
<li><strong>Query the Latest Windows AMI</strong>:
Use the SSM Parameter Store to retrieve the latest AMI ID.</li>
</ol>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">aws ssm get-parameters --names /aws/service/ami-windows-latest/Windows_Server-2016-English-Full-Base --region us-west-2
</span></span></code></pre></div><ol start="2">
<li><strong>Launch an EC2 Instance</strong>:
Embed the command to retrieve the latest AMI ID in your instance launch command.</li>
</ol>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-powershell" data-lang="powershell"><span class="line"><span class="cl"><span class="n">aws</span> <span class="n">ec2</span> <span class="nb">run-instances</span> <span class="p">-</span><span class="n">-image-id</span> <span class="n">resolve</span><span class="err">:</span><span class="n">ssm</span><span class="err">:</span><span class="p">/</span><span class="n">aws</span><span class="p">/</span><span class="n">service</span><span class="p">/</span><span class="nb">ami-windows</span><span class="n">-latest</span><span class="p">/</span><span class="n">Windows_Server</span><span class="p">-</span><span class="mf">2016</span><span class="n">-English-Full-Base</span> <span class="p">-</span><span class="n">-count</span> <span class="mf">1</span> <span class="p">-</span><span class="n">-instance-type</span> <span class="n">t2</span><span class="p">.</span><span class="py">medium</span> <span class="p">-</span><span class="n">-region</span> <span class="nb">us-west</span><span class="p">-</span><span class="mf">2</span>
</span></span></code></pre></div><p>This method ensures that your new instance uses the most current Windows Server 2016 AMI available.</p>
<h2 id="using-ssm-parameters-with-powershell">Using SSM Parameters with PowerShell<a class="heading-anchor" href="#using-ssm-parameters-with-powershell" aria-label="Link to this section"><svg class="icon" viewBox="0 0 24 24" aria-hidden="true"><path d="M10 14a4.5 4.5 0 0 0 6.6.4l2.5-2.5a4.6 4.6 0 0 0-6.5-6.5l-1.4 1.4"/><path d="M14 10a4.5 4.5 0 0 0-6.6-.4L4.9 12a4.6 4.6 0 0 0 6.5 6.5l1.4-1.4"/></svg></a></h2>
<p>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:</p>
<ol>
<li><strong>Retrieve the Latest Windows AMI</strong>:
Use the <code>Get-SSMParameter</code> cmdlet to get the latest AMI ID.</li>
</ol>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-powershell" data-lang="powershell"><span class="line"><span class="cl"><span class="nb">Get-SSMParameter</span> <span class="n">-Name</span> <span class="p">/</span><span class="n">aws</span><span class="p">/</span><span class="n">service</span><span class="p">/</span><span class="nb">ami-windows</span><span class="n">-latest</span><span class="p">/</span><span class="n">Windows_Server</span><span class="p">-</span><span class="mf">2016</span><span class="n">-English-Full-Base</span> <span class="n">-region</span> <span class="nb">us-west</span><span class="p">-</span><span class="mf">2</span>
</span></span></code></pre></div><ol start="2">
<li><strong>Launch the EC2 Instance</strong>:
Use the <code>New-EC2Instance</code> cmdlet, incorporating the latest AMI ID.</li>
</ol>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-powershell" data-lang="powershell"><span class="line"><span class="cl"><span class="nb">New-EC2Instance</span> <span class="n">-ImageId</span> <span class="p">((</span><span class="nb">Get-SSMParameterValue</span> <span class="n">-Name</span> <span class="p">/</span><span class="n">aws</span><span class="p">/</span><span class="n">service</span><span class="p">/</span><span class="nb">ami-windows</span><span class="n">-latest</span><span class="p">/</span><span class="n">Windows_Server</span><span class="p">-</span><span class="mf">2016</span><span class="n">-English-Full-Base</span><span class="p">).</span><span class="n">Parameters</span><span class="p">[</span><span class="mf">0</span><span class="p">].</span><span class="n">Value</span><span class="p">)</span> <span class="n">-InstanceType</span> <span class="n">t2</span><span class="p">.</span><span class="py">medium</span> <span class="n">-AssociatePublicIp</span> <span class="vm">$true</span> <span class="n">-SubnetId</span> <span class="nb">subnet-xxxxxxxx</span> <span class="n">-region</span> <span class="nb">us-west</span><span class="p">-</span><span class="mf">2</span>
</span></span></code></pre></div><p><code>-AssociatePublicIp</code> sets a property of the network interface, so it only
works alongside <code>-SubnetId</code>. Without one the cmdlet errors rather than
picking a default.</p>
<p>Other operating systems have their own parameter paths. For example, Amazon Linux 2 can be found by using <code>/aws/service/ami-amazon-linux-latest/</code>, see the <a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/parameter-store-finding-public-parameters.html" rel="noopener">Finding public parameters</a> on the AWS Docs for more information.</p>
<p>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.</p>
<aside class="book-cta">
  <h2>Pro PowerShell for Amazon Web Services</h2>
  <p>The book I wrote about automating AWS with PowerShell — EC2, S3, CloudWatch, IAM and the rest, worked through end to end. Second edition, from Apress.</p>
  <p><a class="btn" href="https://amzn.to/4iKOQMj" rel="noopener sponsored">Find it on Amazon</a></p>
  <p class="affiliate-disclosure">Affiliate link. If you buy through it I may earn a small commission at no extra cost to you.</p>
</aside>

]]></content:encoded>
    </item>
  </channel>
</rss>
