Python-put_item()S3,Lambda,DynamoDB--发生错误(ValidationException)

Python-put_item()S3,Lambda,DynamoDB--发生错误(ValidationException),python,amazon-web-services,aws-lambda,boto3,Python,Amazon Web Services,Aws Lambda,Boto3,我在AWSS3、lambda和DynamoDB中使用python。我将lambda函数设置为触发器。当我将一个.json文件放入S3存储桶时,它将被激活 当我的函数激活时,一旦到达我的put_item函数调用,它就会出错,该函数调用应该将json对象存储在我的dynamodb表中 错误文本: 我试图更改表中的参数。put_item(TableName='testTable',item=jsonDict),但我之前遵循的文档仅将一个参数传递给此函数 如有任何建议或协助,将不胜感激 我的守则规定:

我在AWSS3、lambda和DynamoDB中使用python。我将lambda函数设置为触发器。当我将一个.json文件放入S3存储桶时,它将被激活

当我的函数激活时,一旦到达我的put_item函数调用,它就会出错,该函数调用应该将json对象存储在我的dynamodb表中

错误文本: 我试图更改
表中的参数。put_item(TableName='testTable',item=jsonDict)
,但我之前遵循的文档仅将一个参数传递给此函数

如有任何建议或协助,将不胜感激

我的守则规定: 云监视日志: 编辑: 我使用“test”主键和“test”表名创建了我的表,将所有其他设置保留在AWS dynamo表创建GUI中的默认设置

json文件内容:
{“test”:{“name”:“Cody”,“age”:27,“car”:true}

您试图使用
{“name”:“Cody”,“age”:27,“car”:true}
作为主键的值。在DynamoDB中,主(分区)键只能是

例如,使用
{“test”:“Cody”,“age”:27,“car”:True}
作为
项目
参数将起作用


或者,如果您将表中的分区键名称更改为
name
,则调用
table.put_item(item=jsonDict['test'])
也会起作用。

错误是,您放入DynamoDB的JSON没有
test
键。请编辑您的问题以显示DynamoDB表的设计(它是否有一个
test
?)和一个加载到
jsonDict
中的数据示例。正如您所说,我重新格式化了我的JSON以包含一个test主键。这很有效。谢谢你,米兰。是的,我很高兴这有帮助。请随意投票并接受答案,以便其他人也能认识到它的帮助。我还需要两个声誉,然后我就可以开始投票了。一旦我得到它,我会立即投票给你的答案。我保证。
[ERROR] ClientError: An error occurred (ValidationException)
when calling the PutItem operation: One or more parameter values
were invalid: Missing the key test in the item
import boto3
import json

s3_client = boto3.client('s3')
dynamodb = boto3.resource('dynamodb')

def lambda_handler(event, context):
    bucket = event['Records'][0]['s3']['bucket']['name']
    json_file_name = event['Records'][0]['s3']['object']['key']
    json_object = s3_client.get_object(Bucket=bucket,Key=json_file_name)
    jsonFileReader = json_object['Body'].read()
    jsonDict = json.loads(jsonFileReader)
    table = dynamodb.Table('test')
    table.put_item(Item = jsonDict)

    return 'Hello from lambda'
[ERROR] ClientError: An error occurred (ValidationException) when
calling the PutItem operation: One or more parameter values were
invalid: Missing the key test in the item
Traceback (most recent call last):

  File "/var/task/lambda_function.py", line 14, in lambda_handler
    response = table.put_item(Item = jsonDict)
  File "/var/runtime/boto3/resources/factory.py", line 520, in do_action
    response = action(self, *args, **kwargs)
  File "/var/runtime/boto3/resources/action.py", line 83, in __call__
    response = getattr(parent.meta.client, operation_name)(**params)
  File "/var/runtime/botocore/client.py", line 320, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/var/runtime/botocore/client.py", line 623, in _make_api_call
    raise error_class(parsed_response, operation_name)