Rod Elias
Rod Elias

Reputation: 746

Error when changing instance type in a python for loop

I have a Python 2 script which uses boto3 library.

Basically, I have a list of instance ids and I need to iterate over it changing the type of each instance from c4.xlarge to t2.micro.

In order to accomplish that task, I'm calling the modify_instance_attribute method.

I don't know why, but my script hangs with the following error message:

EBS-optimized instances are not supported for your requested configuration.

Here is my general scenario:

Say I have a piece of code like this one below:

def change_instance_type(instance_id):
    client = boto3.client('ec2')
    response = client.modify_instance_attribute(
        InstanceId=instance_id,
        InstanceType={
            'Value': 't2.micro'
        }
    )

So, If I execute it like this:

change_instance_type('id-929102')

everything works with no problem at all.

However, strange enough, if I execute it in a for loop like the following

instances_list = ['id-929102']
for instance_id in instances_list:
    change_instance_type(instance_id)

I get the error message above (i.e., EBS-optimized instances are not supported for your requested configuration) and my script dies.

Any idea why this happens?

Upvotes: 0

Views: 105

Answers (1)

Dave Maple
Dave Maple

Reputation: 8402

When I look at EBS optimized instances I don't see that T2 micros are supported:

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSOptimized.html

I think you would need to add EbsOptimized=false as well.

Upvotes: 3

Related Questions