Hi@akhtar,
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
ec2.stop_instances(InstanceIds=[instance_id])
waiter=ec2.get_waiter('instance_stopped')
waiter.wait(InstanceIds=[instance_id])
# Change the instance type
ec2.modify_instance_attribute(InstanceId=instance_id, Attribute='instanceType', Value='t2.small')
# Start the instance
ec2.start_instances(InstanceIds=[instance_id])