Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python AWS Lambda DynamoDB查询错误_Python_Amazon Web Services_Lambda_Amazon Dynamodb - Fatal编程技术网

Python AWS Lambda DynamoDB查询错误

Python AWS Lambda DynamoDB查询错误,python,amazon-web-services,lambda,amazon-dynamodb,Python,Amazon Web Services,Lambda,Amazon Dynamodb,我正在用python编写AWS Lambda函数。我正在使用boto3连接到DynamoDB数据库,并尝试检索最后一个位置条目 DynamoDB表有一个主分区键“Serial”,它是一个字符串,还有一个主排序键“Time”,也是一个字符串 当我运行此代码时,试图获取序列号“0001”的最后一个条目时,我得到以下错误 def getPriorGeofence(device): client = boto3.client('dynamodb') response = client.query(

我正在用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(串行)”
],
[
“/var/task/lambda_function.py”,
110,
“getPriorGeofence”,
“'AttributeValueList':[设备]”
],
[
“/var/runtime/botocore/client.py”,
253,
“_api_调用”,
返回self.\u make\u api\u调用(操作名称,kwargs)
],
[
“/var/runtime/botocore/client.py”,
517,
“_make_api_call”,
api参数,操作模型,上下文=请求上下文
],
[
“/var/runtime/botocore/client.py”,
572,
“\u将\u转换为\u请求\u命令”,
api参数,操作模型
],
[
“/var/runtime/botocore/validate.py”,
270,
“将\u序列化为\u请求”,
“raise ParamValidationError(report=report.generate_report())”
]
],
“errorType”:“ParamValidationError”,
errorMessage:“参数验证失败:\n参数KeyConditions.Serial.AttributeValueList[0]的类型无效,值:0001,类型:,有效类型:
}

如下所述更改AttributeValueList值(即明确将数据类型称为字符串S):-


更改AttributeValueList值,如下所述(即明确地将数据类型称为字符串“S”):-

{
  "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'>"
}
 KeyConditions={
        "Serial":{
            'ComparisonOperator': "EQ",
            'AttributeValueList': [{'S' : device}]
        }
    }