I am using python with the AWS S3, lambda and DynamoDB. I have my lambda function set up as a trigger. When I drop a .json file into my S3 bucket, it will activate.
When my function activates, it errors once it reaches my put_item function call that is supposed to be storing the json object in my dynamodb table.
The error text:
[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
I have tried to change the arguments within the table.put_item(TableName='testTable', Item = jsonDict), but the documents I was following before only passed one argument to this function.
Any advice or assistance would be greatly appreciated.
My Code states:
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'
CLOUD WATCH LOGS:
[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)
EDITS:
I created my table with the 'test' primary key and the 'test' table name, leaving all of the other settings to default within the AWS dynamo table creation GUI.
json file contents:
{ "test": { "name": "Cody", "age": 27, "car": true } }
test. Please edit your question to show the design of the DynamoDB table (does it have a hash key oftest?) and a sample of the data you are loading intojsonDict.