How to modify EC2 Instance Properties using boto3

0 votes

Hi Guys,

I have launched an EC2 instance using boto3. Now I want to modify some properties on that instance. How can I do that?

Oct 7, 2020 in AWS by akhtar
• 38,210 points

1 answer to this question.

0 votes


To modify an EC2 instance, first, you need to stop the instance and wait until it is properly stopped. Then, using the instance id, you can specify the attribute and new value with the 'modify_instance_attribute()' method, which will change the EC2 instance attribute. In your case, that attribute is 'instanceType'. Once that is done, start the instance with the modified properties as shown below.

import boto3
ec2 = boto3.client('ec2')
# choose an EC2 instance with id
instance_id = 'i-05ca5f05f965b3a4b'
# Stop the instance
# Change the instance type
ec2.modify_instance_attribute(InstanceId=instance_id, Attribute='instanceType', Value='t2.small')
# Start the instance
answered Oct 7, 2020 by MD
• 95,300 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,140 points
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How to terminate EC2 instance using boto3?

Hi@akhtar, We can create and modify an EC2 ...READ MORE

answered Oct 7, 2020 in AWS by MD
• 95,300 points