raj*_*jat 1 amazon-ec2 boto amazon-web-services
我可以使用 python boto 来更改我的实例的关闭行为:
基本上,我们从 Web 界面更改的内容相同:
我用来运行实例的代码是:
# Create and run a instance based on our predefined image
reservation= conn.run_instances(
'ami-0072ee30',
key_name='rajat',
instance_type=instance_requested_type)
Run Code Online (Sandbox Code Playgroud)
Spot 实例请求:
reservs = conn.request_spot_instances(
float(max_bid),
'ami-0072ee30',
count=1,
type='one-time',
instance_type=instance_requested_type)
Run Code Online (Sandbox Code Playgroud)
是的你可以。run_instances
调用的方法有一个可选参数,其instance_initiated_shutdown_behavior
值为"stop"
or "terminate"
。因此,要扩展上面的示例以指定您希望实例在用户终止时停止,您可以执行以下操作:
import boto3
ec2_client = boto3.client('ec2')
reservation = ec2_client.run_instances(
ImageId='ami-0072ee30',
MinCount=1,
MaxCount=1,
KeyName='rajat',
InstanceType='t2.micro',
InstanceInitiatedShutdownBehavior='terminate'
)
Run Code Online (Sandbox Code Playgroud)
参考:https : //boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html
归档时间: |
|
查看次数: |
961 次 |
最近记录: |