是否可以通过AWSCLI(用户数据)运行python脚本。我尝试过,但它没有运行,我的日志中有以下内容
boot.log:2015-08-07 10:08:30,660 - __init__.py[WARNING]: Unhandled non-multipart (text/x-not-multipart) userdata: './step-1
cloud-init.log:2015-08-07 10:08:30,660 - __init__.py[WARNING]: Unhandled non-multipart (text/x-not-multipart) userdata: './step-1'
cloud-init-output.log:2015-08-07 10:08:30,660 - __init__.py[WARNING]: Unhandled non-multipart (text/x-not-multipart) userdata: './step-1'
注意步骤 1 是我的脚本,我试图将其作为用户数据传递。另外,我的脚本存在于我运行命令的同一目录中,因此它应该选择
默认解释器似乎是Python。因此,如果您只想执行 shell 脚本,则需要以 hash-bang 开头,例如:
#!/bin/bash
/yourpath/step-1
请注意,为了调试此问题,请尝试:cat /var/log/cloud-init-output.log 请参阅:https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html#user-data-shell-scripts
您可以使用在
user-data
下运行的任何命令。我已使用 user-data
通过域控制器设置或使用 PowerShell 加入域来引导 Windows 实例;当然,考虑到它是在 EC2 上 - 无论您是在基于 Unix 还是基于 Windows 中运行,这些属性都是可扩展的。
因此您已指定 Python - 所以请确保以下内容
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html
aws 的文档说仅支持 shell 和 cloud-init 指令
Unhandled non-multipart (text/x-not-multipart) userdata: 'b'IyE
如果您在 AL 2023 中遇到此错误,您可能会在 Base64 中对用户数据进行双重编码。我就是这种情况。请参阅https://github.com/amazonlinux/amazon-linux-2023/issues/401
Boto 文档还警告您不必对用户数据进行编码
该值将自动进行 Base64 编码。在执行操作之前请勿对该值进行 Base64 编码。