gpt4 book ai didi

amazon-dynamodb - Boto 扫描过滤器表达式 : Invalid type for parameter

转载 作者:行者123 更新时间:2023-12-03 23:22:25 24 4
gpt4 key购买 nike

我正在尝试使用以下代码,但无法使其正常工作。它一直给我一条关于过滤器表达式类型不正确的错误消息,即使我正在做的正是在 the documentation 中所做的。 .我能做些什么来解决这个问题?

def EndpointDeleted(event):
endpoint = event['Attributes']['EndpointArn']
if('EndpointArn' in event['Attributes']):
client = boto3.client('dynamodb')
response = client.scan(
TableName='sniffergps-mobilehub-812282467-Users',
Select='ALL_ATTRIBUTES',
FilterExpression=Attr('Endpoints').contains(endpoint)
)
return response


但是我收到一条错误消息,指出过滤器表达式的类型不正确。我有以下导入消息: import boto3
from boto3.dynamodb.conditions import Key
from boto3.dynamodb.conditions import Attr

错误信息:

{
"errorMessage": "Parameter validation failed:\nInvalid type for parameter FilterExpression, value: <boto3.dynamodb.conditions.Contains object at 0x7fdca25e0b38>, type: <class 'boto3.dynamodb.conditions.Contains'>, valid types: <class 'str'>",
"errorType": "ParamValidationError",
"stackTrace": [
[
"/var/task/lambda_function.py",
13,
"lambda_handler",
"return EndpointDeleted(event)"
],
[
"/var/task/lambda_function.py",
24,
"EndpointDeleted",
"FilterExpression=Attr('Endpoints').contains(endpoint)"
],
[
"/var/runtime/botocore/client.py",
312,
"_api_call",
"return self._make_api_call(operation_name, kwargs)"
],
[
"/var/runtime/botocore/client.py",
575,
"_make_api_call",
"api_params, operation_model, context=request_context)"
],
[
"/var/runtime/botocore/client.py",
630,
"_convert_to_request_dict",
"api_params, operation_model)"
],
[
"/var/runtime/botocore/validate.py",
291,
"serialize_to_request",
"raise ParamValidationError(report=report.generate_report())"
]
]
}

最佳答案

请注意 Boto3 DynamoDB 之间的语法差异 Client ,以及表 Resource .
FilterExpression DynamoDB 客户端的参数需要一个字符串。

您用来设置 FilterExpression 的方法参数看起来像您使用 DynamoDB.Table 资源的方式。

关于amazon-dynamodb - Boto 扫描过滤器表达式 : Invalid type for parameter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46796097/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com