使用boto python更改关闭行为EC2 python实例

时间:2013-10-16 12:26:27

标签: amazon-web-services amazon-ec2 boto

我可以使用python boto来更改我的实例的关闭行为:

基本上,我们从网络界面改变了同样的事情:

enter image description here

我用来运行实例的代码是:

   # 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)

1 个答案:

答案 0 :(得分:3)

是的,你可以。名为run_instances的{​​{1}}方法有一个可选参数,其值可以为instance_initiated_shutdown_behavior"stop"。因此,要扩展上面的示例以指定您希望实例在用户终止时停止,您可以这样做:

"terminate"

参考:https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html