我正在尝试使用boto3(环境Python 3.5,Windows 7)提交EC2 SPOT实例的请求 . 我需要传递 UserData 参数来运行初始脚本 .
我得到的错误是文件"C:\Users...\Python\Python35\lib\site-packages\botocore\client.py",第222行,在_make_api_call中引发ClientError(parsed_response,operation_name)botocore.exceptions.ClientError:调用 RequestSpotInstances operation: Invalid BASE64 encoding of user data Code 时发生错误(InvalidParameterValue)
我正在关注此文档https://boto3.readthedocs.io/en/latest/reference/services/ec2.html#EC2.Client.request_spot_instances
If I take the UserData parameter out – everything works well.
我尝试了不同的方法来传递参数,但我最终得到了相同的错误 .
Boto 3 Script
client = session.client('ec2')
myparam = str(base64.b64encode(bytes('yum install -y php', 'utf-8')))
response = client.request_spot_instances(
SpotPrice='0.4',
InstanceCount=1,
Type='one-time',
LaunchSpecification={
'ImageId': 'ami-xxxxxx',
'KeyName': 'xxxxx',
'InstanceType': 't1.micro',
'UserData': myparam,
'Monitoring': {
'Enabled': True
}
})
1 回答
我认为你不应该将你的base64字符串转换为
str
. 你在使用Python 3吗?更换:
通过: