Issue
I am trying to delete the instance using boto3
According to the documentation, there are two methods for deleting the instance using boto3.
terminate()
terminate_instances
What is the difference between these two methods and which one should I use for deleting the instance?
Using terminate_instances() throws the following error:
AttributeError: 'ec2.ServiceResource' object has no attribute 'terminate_instances'
import boto3
ec2 = boto3.resource('ec2')
Instances = ec2.terminate_instances(InstanceIds=['i-xxxxxxxx'])
print(Instances)
What is the correct way to delete the instance using boto3?
Solution
The difference is simply the caller of the function.
The terminate
function is performed on a collection of instances you have already retrieved.
The terminate_instances
function is performed from the client, and requires you to specify the filter of which instances you need to terminate.
Answered By - Chris Williams