I want to teminate many AWS ec2 instance,then i use boto3 like this:
#!/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)
But I got a ERROR:
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.
please tell me how to modify the disableApiTermination.