【发布时间】:2017-11-01 17:21:39
【问题描述】:
我在 AWS Lambda 上有一个简单的 Python 函数,它只是将一些数据放入 DynamoDB 表中,据我所知,我按照 put_item() 函数的 Boto3 文档遵循正确的格式。我收到以下似乎无法调试的错误:
"errorMessage":
"Parameter validation failed:\nInvalid type for parameter
Item.GSRResults.L[0], value: 3.8, type: <class 'float'>, valid types: <class 'dict'>
\nInvalid type for parameter Item.GSRResults.L[1], value: 3.4, type: <class 'float'>, valid types: <class 'dict'>\... snip...
\nInvalid type for parameter Item.GSRResults.L[9], value: 3.3, type: <class 'float'>, valid types: <class 'dict'>",
"errorType": "ParamValidationError",
"stackTrace": [
[
"/var/task/index.py",
39,
"upload_test",
"Item=item"
],
这里是 Python 函数:
def upload_test(event, context):
if event['httpMethod'] == 'POST':
info = event['body']
item = info['Item']
return respond(None, dynamo.put_item(
TableName="TestResults",
Item=item))
这是我发送的 JSON:
{
"body": {
"Item": {
"UID": {
"S": "U999999"
},
"PID": {
"S": "P444444"
},
"GSRResults": { "L": [3.8,3.4,3.3,2.8,1.3,3.2,4.3,2.1,3.2,3.3] }
}
},
"httpMethod": "POST"
}
【问题讨论】:
-
DynamoDB 不允许插入浮点值。
-
@Asdfg 感谢您的回复。在文档中他们给出的示例之一:
"L": ["Cookies", "Coffee", 3.14159] -
Dynamodb 确实允许将浮点值存储为数字。
-
该示例可能不适用于 Python。 Python 将 3.8 视为浮点数,而其他可能将其视为十进制。我想,但我在这里可能是错的。
-
如果我将这些值更改为 int's 或 str's,我仍然会遇到不同类型的相同错误。
标签: python json amazon-web-services amazon-dynamodb aws-lambda