title: sending powershell script to Windows ec2 in user data
body: <p>I'm following <a href="http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/UsingConfig_WinAMI.html" rel="noreferrer">these instructions</a> to bootstrap a Windows ec2 instance with a powershell script (call it "bootstrap.ps1"). However, it looks as if the script has never run when I log into the machine for the first time. I check C:\Program Files\Amazon\Ec2ConfigService\Logs\Ec2ConfigLog, and I see this:</p>
  
  <pre><code>2014-03-11 00:08:02: Ec2HandleUserData: Start running user scripts
  2014-03-11 00:08:02: Ec2HandleUserData: Could not find &lt;script&gt; and &lt;/script&gt;
  2014-03-11 00:08:02: Ec2HandleUserData: Could not find &lt;powershell&gt; and &lt;/powershell&gt;
  </code></pre>
  
  <p>This is what my script looks like:</p>
  
  <pre><code>&lt;powershell&gt;
  (multiple lines of powershell script here)
  &lt;/powershell&gt;
  </code></pre>
  
  <p>I'm base64-encoding the script in Python and sending it through <a href="http://boto.readthedocs.org/en/latest/index.html" rel="noreferrer">boto</a>:</p>
  
  <pre><code>import base64
  # (create connection to aws region in boto called 'conn')
  conn = ...
  # run the instance and provide base64-encoded bootstrap powershell script in user_data
  with open("bootstrap.ps1", "r") as fd:
    conn.run_instances(..., user_data=base64.encodestring(fd.read()))
  </code></pre>
  
  <p>I've made sure that:</p>
  
  <ol>
  <li>The script I'm sending ("bootstrap.ps1") is using \r\n as line endings</li>
  <li>The script available at <code>http://169.254.169.254/latest/user-data</code> base64-decoded is the same as the raw "bootstrap.ps1" I've written (verified by downloading it, then running through <code>base64.decodestring</code> in Python)</li>
  <li>There are no characters before or after <code>&lt;powershell&gt;</code> and <code>&lt;/powershell&gt;</code> in "boostrap.ps1", respectively.</li>
  </ol>
  
  <p>Clearly, I'm including <code>&lt;powershell&gt;</code> and <code>&lt;/powershell&gt;</code> in user_data. These are encoded base-64, yet somehow they're not being found by ec2config? Can anyone see what I'm doing wrong here?</p>