How to delete an EC2 instance using Python boto3

+1 vote
How can I delete an EC2 instance using Python boto3?

Can someone help me with the code?
Dec 3, 2018 in AWS by Nitesh
• 3,080 points
8,386 views

1 answer to this question.

0 votes

You just need to have the list of instances that you want to delete and then pass it as an argument and you are done.

you can use the following code for the same:

import boto3
ids = ['i-1','i-2','i-3','i-4','i-5']
ec2 = boto3.resource('ec2')
ec2.instances.filter(InstanceIds = ids).terminate()

This will serve the purpose. Hope this helps.

answered Dec 3, 2018 by Nabarupa

Related Questions In AWS

+1 vote
1 answer
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,100 points
3,457 views
0 votes
1 answer

How to create an EC2 instance using Python?

Hey JunDevOps, Have a look these scripts: 1. ...READ MORE

answered Jun 24, 2019 in AWS by Aysha

edited Jun 25, 2019 9,216 views
0 votes
1 answer

AWS S3 uploading hidden files by default

versioning is enabled in your bucket. docs.aws.amazon.com/AmazonS3/latest/user-guide/….... the ...READ MORE

answered Oct 4, 2018 in AWS by Priyaj
• 58,100 points
5,858 views
–1 vote
1 answer

How to decrypt the encrypted S3 file using aws-encryption-cli --decrypt

Use command : aws s3 presign s3://mybucket/abc_count.png you get ...READ MORE

answered Oct 22, 2018 in AWS by Priyaj
• 58,100 points
5,156 views
0 votes
1 answer

Import my AWS credentials using python script

Using AWS Cli  Configure your IAM user then ...READ MORE

answered Nov 16, 2018 in AWS by Jino
• 5,820 points
2,825 views
0 votes
2 answers
0 votes
1 answer
0 votes
1 answer

How to safely upgrade an Amazon EC2 instance from t1.micro to large?

Using AWS Management Console: Right-Click on the instance Instance ...READ MORE

answered Oct 8, 2018 in AWS by Priyaj
• 58,100 points
1,070 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