[英]AWS Lambda DynamoDB Query Error
I am programming an AWS Lambda function in python. 我在python中编写AWS Lambda函数。 I am using boto3 to connect to the DynamoDB database and I am trying to retrieve the last location entry. 我正在使用boto3连接到DynamoDB数据库,我正在尝试检索最后一个位置条目。
The DynamoDB table is has a primary partition key of "Serial" which is a string, and a primary sort key of "Time", also a string. DynamoDB表的主分区键是“Serial”,它是一个字符串,主分类键是“Time”,也是一个字符串。
When I run this code, trying to get the last entry for serial "0001" I get the following error 当我运行此代码,尝试获取串行“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
Error 错误
{
"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'>"
}
Change the AttributeValueList value as mentioned below (ie mentioning the data type as String 'S' explicitly):- 如下所述更改AttributeValueList值(即明确地将数据类型称为字符串'S'): -
KeyConditions={
"Serial":{
'ComparisonOperator': "EQ",
'AttributeValueList': [{'S' : device}]
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.