python boto3参数验证错误 [英] python boto3 parameter validation error
问题描述
在这里,我编写了一个python程序来启动一个符合所有条件的实例.但是在执行程序时显示以下错误. botocore.exceptions.ParamValidationError:参数验证失败:参数InstanceIds的无效类型,值:i-012345678,类型:< type'str'> ;,有效类型:< type'list'> ;,< type'tuple'>
.下面是我的代码:
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)`
推荐答案
错误本身是不言自明的.您必须传递实例ID的列表或元组,而不只是字符串.您可以在文档
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])`
这篇关于python boto3参数验证错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!