【发布时间】:2014-04-14 09:17:42
【问题描述】:
我正在关注 these instructions 以使用 powershell 脚本(称为“bootstrap.ps1”)引导 Windows ec2 实例。但是,当我第一次登录机器时,脚本似乎从未运行过。我检查了 C:\Program Files\Amazon\Ec2ConfigService\Logs\Ec2ConfigLog,我看到了这个:
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>
这是我的脚本的样子:
<powershell>
(multiple lines of powershell script here)
</powershell>
我正在用 Python 对脚本进行 base64 编码并通过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()))
我已经确定:
- 我发送的脚本 ("bootstrap.ps1") 使用 \r\n 作为行尾
-
http://169.254.169.254/latest/user-database64-decoded 提供的脚本与我编写的原始“bootstrap.ps1”相同(通过下载验证,然后在 Python 中通过base64.decodestring运行) - “boostrap.ps1”中的
<powershell>和</powershell>之前或之后分别没有字符。
显然,我在 user_data 中包含了 <powershell> 和 </powershell>。这些是 base-64 编码的,但不知何故,ec2config 找不到它们?谁能看到我在这里做错了什么?
【问题讨论】:
标签: python windows powershell amazon-web-services amazon-ec2