Manually enable/ disable for 100 Instance is difficult task:

to overcome this task we have some automated process.

It’s possible automate the process and in one short using python SDK.

list of Ec2 instances:

python code:

import boto3

def disable_termination_protection(instance_id):
ec2 = boto3.client(‘ec2’)
response = ec2.modify_instance_attribute(
InstanceId=instance_id,
DisableApiTermination={
‘Value’: False
}
)
print(f”Termination protection disabled for instance {instance_id}”)

# Get running instances
ec2 = boto3.client(‘ec2’)
response = ec2.describe_instances(
Filters=[
{
‘Name’: ‘instance-state-name’,
‘Values’: [‘running’]
}
]
)

# Disable termination protection for each running instance
for reservation in response[‘Reservations’]:
for instance in reservation[‘Instances’]:
instance_id = instance[‘InstanceId’]
disable_termination_protection(instance_id)

Above code provide will find the running instance and disable the instance termination

After executing we can check this manually for any random 5 instances .

Happy learning!!