sending powershell script to Windows ec2 in user data

Question:

I’m following these instructions 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:

This is what my script looks like:

I’m base64-encoding the script in Python and sending it through boto:

I’ve made sure that:

  1. The script I’m sending (“bootstrap.ps1”) is using \r\n as line endings
  2. The script available at http://169.254.169.254/latest/user-data base64-decoded is the same as the raw “bootstrap.ps1” I’ve written (verified by downloading it, then running through base64.decodestring in Python)
  3. There are no characters before or after <powershell> and </powershell> in “boostrap.ps1”, respectively.

Clearly, I’m including <powershell> and </powershell> 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?

Answer:

The problem lies in the encoding of user_data, which is already performed by boto. According to the boto documentation, user_data should be “[t]he Base64-encoded MIME user data to be made available to the instance(s) in this reservation,” which I find to be very misleading, since the encoding need not and should not be done in the call to run_instances. The following Python works for me now:

Source:

sending powershell script to Windows ec2 in user data by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply