llo*_*ett 5 python windows powershell amazon-ec2 amazon-web-services
我按照这些说明使用powershell脚本引导Windows ec2实例(称之为"bootstrap.ps1").但是,当我第一次登录计算机时,看起来好像脚本从未运行过.我检查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>
Run Code Online (Sandbox Code Playgroud)
这是我的脚本的样子:
<powershell>
(multiple lines of powershell script here)
</powershell>
Run Code Online (Sandbox Code Playgroud)
我是用Python编写脚本的64位编码并通过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()))
Run Code Online (Sandbox Code Playgroud)
我已经确定:
http://169.254.169.254/latest/user-database64解码时可用的脚本与我编写的原始"bootstrap.ps1"相同(通过下载验证,然后base64.decodestring在Python中运行)<powershell>,并</powershell>在"boostrap.ps1"分别.很显然,我包括<powershell>和</powershell>在USER_DATA.这些是编码的base-64,但不知何故ec2config找不到它们?谁能看到我在这里做错了什么?
问题在于编码user_data,已经执行了boto.根据boto文档,user_data应该是" 将这个Base64编码的MIME用户数据提供给此预留中的实例 ",我发现这是非常误导的,因为编码不需要也不应该在致电中完成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())
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4308 次 |
| 最近记录: |