Submitting powershell script in Windows ec2 in user data

I follow these instructions to boot an instance of Windows ec2 using a powershell script (name it "bootstrap.ps1"). However, it seems like the script never runs when it first logs in. I check C: \ Program Files \ Amazon \ Ec2ConfigService \ Logs \ Ec2ConfigLog and I see this:

2014-03-11 00:08:02: Ec2HandleUserData: Start running user scripts
2014-03-11 00:08:02: Ec2HandleUserData: Could not find <script> and </script>
2014-03-11 00:08:02: Ec2HandleUserData: Could not find <powershell> and </powershell>

Here is what my script looks like:

<powershell>
(multiple lines of powershell script here)
</powershell>

I have a base64 coding script in Python and sending it via boto :

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()))

I made sure that:

  • script I submit ("bootstrap.ps1") uses \ r \ n as line endings
  • script, http://169.254.169.254/latest/user-data base64-, "bootstrap.ps1", (, , base64.decodestring Python)
  • <powershell> </powershell> "boostrap.ps1" .

, <powershell> </powershell> user_data. base-64, - ec2config? - , ?

+4
1

user_data, boto. boto, user_data "[t], MIME, Base64, () ,", , , , , run_instances. Python :

# create connection...
conn = ...
# run instance
with open("bootstrap.ps1", "r") as fd:
  # don't encode user_data
  conn.run_instances(..., user_data=fd.read())
+6

Source: https://habr.com/ru/post/1531078/


All Articles