简体   繁体   English

参数验证失败:\\n参数 Filters[0].Values[0] 的类型无效,值:{},类型:<class 'dict'> , 有效类型:<class 'str'>

[英]Parameter validation failed:\nInvalid type for parameter Filters[0].Values[0], value: {}, type: <class 'dict'>, valid types: <class 'str'>

I have the following code in AWS lambda.我在 AWS lambda 中有以下代码。

from operator import itemgetter

import boto3

client = boto3.client('ec2')

def lambda_handler(name='test*', owner='**********'):
    list_of_images = client.describe_images(Filters=[{'Name': 'name', 'Values':
    [name, ]}, {'Name': 'owner-id', 'Values': [owner, ]}])
    image_details = sorted(list_of_images['Images'], key=itemgetter(
    'CreationDate'), reverse=True)
    return image_details[0]  

I am not familiar with python.我对python不熟悉。 when I run this every time I get following error.当我每次遇到以下错误时运行它。

{
    "errorMessage": "Parameter validation failed:\nInvalid type for parameter Filters[0].Values[0], value: {}, type: <class 'dict'>, valid types: <class 'str'>\nInvalid type for parameter Filters[1].Values[0], value: <__main__.LambdaContext object at 0x7fb272a686a0>, type: <class '__main__.LambdaContext'>, valid types: <class 'str'>",
    "errorType": "ParamValidationError",
    "stackTrace": [
    "  File \"/var/task/lambda_function.py\", line 10, in lambda_handler\n    list_of_images = client.describe_images(Filters=[{'Name': 'name', 'Values':\n",
    "  File \"/var/runtime/botocore/client.py\", line 357, in _api_call\n    return self._make_api_call(operation_name, kwargs)\n",
    "  File \"/var/runtime/botocore/client.py\", line 648, in _make_api_call\n    request_dict = self._convert_to_request_dict(\n",
    "  File \"/var/runtime/botocore/client.py\", line 696, in _convert_to_request_dict\n    request_dict = self._serializer.serialize_to_request(\n",
    "  File \"/var/runtime/botocore/validate.py\", line 293, in serialize_to_request\n    raise ParamValidationError(report=report.generate_report())\n"
    ]
}

Boto is picky about parameter types, but at least the error message describes what is expected. Boto 对参数类型很挑剔,但至少错误消息描述了预期的内容。

I think you are mistakenly passing name as something other than a string.我认为您错误地将名称作为字符串以外的其他内容传递。 ec2 describe-instances does not have a name filter, perhaps you need to filter on tag:Name ? ec2 describe-instances 没有名称过滤器,也许您需要过滤 tag:Name ?

eg例如

name='Webserver'
owner='123456789012'

list_of_images = client.describe_images(Filters=[ {'Name': 'tag:Name', 'Values': [name] } , {'Name': 'owner-id', 'Values': [owner] } ])

Alternatively pass in dict parameters或者传入 dict 参数

names=['Webserver']
owners=['123456789012']
list_of_images = client.describe_images(Filters= [ {'Name': 'tag:Name', 'Values': names }, {'Name': 'owner-id', 'Values': owners } ])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 参数验证失败:参数 Key 的类型无效。,值:,类型:<class 'str'> ,有效类型:<class 'dict'></class></class> - Parameter validation failed: Invalid type for parameter Key., value: , type: <class 'str'>, valid types: <class 'dict'> Lambda python 3.7:参数验证失败:\\ n参数Dimensions [0]的类型无效 - Lambda python 3.7 : Parameter validation failed:\nInvalid type for parameter Dimensions[0] 获取错误参数 Item 的类型无效,值:类型:<class 'list'> , 有效类型:<class 'dict'> 将 S3 加载到 DynamoDB 时 - Getting error Invalid type for parameter Item, value: type: <class 'list'>, valid types: <class 'dict'> while loading S3 to DynamoDB “ TypeError:未知参数类型: <class 'dict_values'> ” - “TypeError: Unknown parameter type: <class 'dict_values'>” 为什么参数类型“Dict [str,Union [str,int]]”不接受“Dict [str,str]”类型的值(mypy) - Why doesn't parameter type "Dict[str, Union[str, int]]" accept value of type "Dict[str, str]" (mypy) to_dict('records') 导致不支持的类型:<class 'str'> 错误</class> - to_dict('records') causing unsupported type: <class 'str'> error “datetime”类型的参数不能分配给“str”类型的参数“value” - Argument of type "datetime" cannot be assigned to parameter "value" of type "str" 打印具有类型的对象中的特定值<class 'str'> - Printing specific values in an object with type <class 'str'> 熊猫“类型<class 'str'> ” - Pandas “type of <class 'str'>” to_datetime 无法识别的值类型:<class 'str'></class> - to_datetime Unrecognized value type: <class 'str'>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM