我可以使用python boto来更改我的实例的关闭行为:
基本上,我们从网络界面改变了同样的事情:
我用来运行实例的代码是:
# Create and run a instance based on our predefined image
reservation= conn.run_instances(
'ami-0072ee30',
key_name='rajat',
instance_type=instance_requested_type)
现场实例请求:
reservs = conn.request_spot_instances(
float(max_bid),
'ami-0072ee30',
count=1,
type='one-time',
instance_type=instance_requested_type)
答案 0 :(得分:3)
是的,你可以。名为run_instances
的{{1}}方法有一个可选参数,其值可以为instance_initiated_shutdown_behavior
或"stop"
。因此,要扩展上面的示例以指定您希望实例在用户终止时停止,您可以这样做:
"terminate"
参考:https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html