小编Chr*_*han的帖子

如何通过boto3更改终止保护

我想终止许多AWS ec2实例,然后我像这样使用boto3:

#!/usr/bin/env python 
#coding=utf8

import boto3
ec2 = boto3.resource(
    'ec2',
    aws_access_key_id="<AK>",
    aws_secret_access_key="<SK>",
    region_name='eu-central-1'
)

instances = ec2.instances.filter(
    Filters=[{'Name': 'instance-state-name', 'Values': ['stopped']}])

ids = ['id1','id2'.....'idn']
status = ec2.instances.filter(InstanceIds=ids).terminate()
print(status)
Run Code Online (Sandbox Code Playgroud)

但我收到一个错误:

botocore.exceptions.ClientError: An error occurred (OperationNotPermitted) when calling the TerminateInstances operation: The instance 'i-0f06b49c1f16dcfde' may not be terminated. Modify its 'disableApiTermination' instance attribute and try again.
Run Code Online (Sandbox Code Playgroud)

请告诉我如何修改disableApiTermination。

amazon-ec2 amazon-web-services boto3

5
推荐指数
1
解决办法
5865
查看次数

标签 统计

amazon-ec2 ×1

amazon-web-services ×1

boto3 ×1