How to terminate EC2 instance using boto3

0 votes

Hi Guys,

I have launched some EC2 instances. Now I want to terminate these instances using boto3. How can I do that?

Oct 7, 2020 in AWS by akhtar
• 38,230 points
5,831 views

1 answer to this question.

0 votes

Hi@akhtar,

We can create and modify an EC2 instance using boto3 also provided a method to terminate instances that are no longer required. If the following code sample is saved in a python file ec2.py,

import boto3, sys
ec2 = boto3.resource('ec2')
# iterate through instance IDs and terminate them
for id in sys.argv[1:]:
 instance = ec2.Instance(id)
 print(instance.terminate())
answered Oct 7, 2020 by MD
• 95,440 points

Related Questions In AWS

0 votes
1 answer

How to Pass the VPC ID while creating the Ec2 instance in AWS using Python Boto3

import boto3 ec2 = boto3.resource('ec2') instance = ec2.create_instances( ...READ MORE

answered Jan 29, 2019 in AWS by Priyaj
• 58,090 points
2,928 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How to modify EC2 Instance Properties using boto3?

Hi@akhtar, To modify an EC2 instance, first, you ...READ MORE

answered Oct 7, 2020 in AWS by MD
• 95,440 points
2,907 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP