Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python boto3 parameter validation error

Here I have written a python program to start an instance that matches all the conditions. But The following error is displayed while executing the program.botocore.exceptions.ParamValidationError: Parameter validation failed: Invalid type for parameter InstanceIds, value: i-012345678, type: <type 'str'>, valid types: <type 'list'>, <type 'tuple'> .Below is my code:

import boto3
ec2=boto3.client('ec2',region_name='ap-south-1')
a=ec2.describe_instances()
for i in a['Reservations']:
    for x in i['Instances']:
       if x['InstanceId']=="i-12345678" and x['State'['Name']=='stopped':
            n = x['InstanceId']
            ec2.start_instances(InstanceIds=n)`
like image 434
vishal Avatar asked May 02 '26 05:05

vishal


1 Answers

The error itself is self-explanatory. You have to pass a list or tuple of instance ids rather than just string. You can see this in the docs

See the updated code below.

import boto3
ec2=boto3.client('ec2',region_name='ap-south-1')
a=ec2.describe_instances()
for i in a['Reservations']:
    for x in i['Instances']:
       if x['InstanceId']=="i-12345678" and x['State'['Name']=='stopped':
            n = x['InstanceId']
            ec2.start_instances(InstanceIds=[n])`
like image 67
Arpit Solanki Avatar answered May 03 '26 18:05

Arpit Solanki



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!