[英]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.