我在python中编写AWS Lambda函数。我正在使用boto3连接到DynamoDB数据库,我正在尝试检索最后一个位置条目。
DynamoDB表的主分区键为" Serial"这是一个字符串,以及" Time"的主要排序键,也是一个字符串。
当我运行此代码时,尝试获取序列号的最后一个条目" 0001"我收到以下错误
def getPriorGeofence(device):
client = boto3.client('dynamodb')
response = client.query(
TableName='Locations',
IndexName='Serial',
Select='ALL_ATTRIBUTES',
Limit=1,
ScanIndexForward=True,
KeyConditions={
"Serial":{
'ComparisonOperator': "EQ",
'AttributeValueList': [device]
}
}
)
return response
错误
{
"stackTrace": [
[
"/var/task/lambda_function.py",
154,
"lambda_handler",
"priorGeofence = getPriorGeofence(serial)"
],
[
"/var/task/lambda_function.py",
110,
"getPriorGeofence",
"'AttributeValueList': [device]"
],
[
"/var/runtime/botocore/client.py",
253,
"_api_call",
"return self._make_api_call(operation_name, kwargs)"
],
[
"/var/runtime/botocore/client.py",
517,
"_make_api_call",
"api_params, operation_model, context=request_context)"
],
[
"/var/runtime/botocore/client.py",
572,
"_convert_to_request_dict",
"api_params, operation_model)"
],
[
"/var/runtime/botocore/validate.py",
270,
"serialize_to_request",
"raise ParamValidationError(report=report.generate_report())"
]
],
"errorType": "ParamValidationError",
"errorMessage": "Parameter validation failed:\nInvalid type for parameter KeyConditions.Serial.AttributeValueList[0], value: 0001, type: <type 'unicode'>, valid types: <type 'dict'>"
}
答案 0 :(得分:0)
如下所述更改AttributeValueList值(即明确提及数据类型为String&#39; S&#39;)
KeyConditions={
"Serial":{
'ComparisonOperator': "EQ",
'AttributeValueList': [{'S' : device}]
}
}