我想终止许多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。