[英]Parameter validation failed: Invalid type for parameter Key., value: , type: <class 'str'>, valid types: <class 'dict'>
[英]Parameter validation failed:\nInvalid type for parameter Filters[0].Values[0], value: {}, type: <class 'dict'>, valid types: <class 'str'>
我在 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]
我对python不熟悉。 当我每次遇到以下错误时运行它。
{
"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 对参数类型很挑剔,但至少错误消息描述了预期的内容。
我认为您错误地将名称作为字符串以外的其他内容传递。 ec2 describe-instances 没有名称过滤器,也许您需要过滤 tag:Name ?
例如
name='Webserver'
owner='123456789012'
list_of_images = client.describe_images(Filters=[ {'Name': 'tag:Name', 'Values': [name] } , {'Name': 'owner-id', 'Values': [owner] } ])
或者传入 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.