How to stop EC2 instances using Boto3

0 votes

Hi Guys,

I have launched EC2 instances in AWS. I am new to the boto3 module. I want to stop an instance using boto3. How can I do that?

Oct 7, 2020 in AWS by akhtar
• 38,260 points
2,322 views

1 answer to this question.

0 votes

Hi@akhtar,

To change the state of an EC2 instance you have to target it using the EC2 instance id, bypassing the id to the 'Instance()' method and then using the 'stop()' method to stop the EC2 instance.

import boto3
ec2 = boto3.resource('ec2')
ec2.Instance('instance_ID').stop()
answered Oct 7, 2020 by MD
• 95,460 points

Related Questions In AWS

+1 vote
2 answers
0 votes
1 answer
0 votes
1 answer

How can I return XML from boto calls?

I don't think there's an officially supported ...READ MORE

answered Jul 20, 2018 in AWS by Cloud gunner
• 4,670 points
1,481 views
0 votes
1 answer

How to describe EC2 instances using Boto3?

Hi@akhtar, An EC2 instance is a virtual server ...READ MORE

answered Oct 8, 2020 in AWS by MD
• 95,460 points
6,820 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