Skip to content
Advertisement

An error occurred (ValidationException) when calling the PutItem operation: One or more parameter values were invalid: Missing the key CreatedAt

Help, I am totally perplexed as to why I am getting this error indicating that CreateAt field is missing when a PutItem() is called. I an ingesting emails into an S3 bucket which are then taken from the S3 and loaded into the Dynamo log table. Once that is completed, the record is then uploaded to Salesforce as a lead record. The upload to Salesforce works correctly but along the way I get this error when writing to the Dynamo log table.

I used AWS Console to create my DynamoDB log table to define both the partition key (CogId) and Sort key (CreatedAt)

enter image description here

I then use the following python function code to add my data – self.data – to DynamoDBlog table using the Put Item function. The data includes the CreatedAt key and its value self.now which contains the string value of datetime.now()

  #Records Processed Logs
def processed_records_logging(self,action,object_type,object_id,existing_payload=None):
    print('processed_records_logging')
    print(self.global_payload)
    try:
        self.random_id = urandom(20).hex()
        self.now = str(datetime.now())
        self.detailResult = self.global_payload['Records'][0]['dynamodb']['NewImage']['Information']
        self.ext_id = '-'
        if 'ExternalId' in self.global_payload['Records'][0]['dynamodb']['NewImage']:
            self.ext_id = self.global_payload['Records'][0]['dynamodb']['NewImage']['ExternalId']
        self.data = {'CogId' : self.random_id, 'Month': self.today_month,'Year': self.today_year,'Day': self.today_date, 'LinkingCogId' : self.global_payload['Records'][0]['dynamodb']['NewImage']['CogId'], 'Action': action, 'Object': object_type, 'Id':object_id, 'NewInformation' : self.detailResult, 'Result': 'Pass', 'CreatedAt': self.now, 'ExternalId' : self.ext_id}
        print('data in processed')
        print('<< SELF DATA>> ',self.data)
        # self.data['DuplicateUpdateInfo'] = {'result': None}
        # self.data['DuplicateExistingInfo'] = {'result': None}
        # self.data['Message'] = {'result': None}
        if existing_payload != None:
            self.data['OldInformation'] = existing_payload
        # else:
        #   self.data['OldInformation'] = {'result': None}
        print(self.data)
        self.response = self.logItem.put_item(Item = self.data)
        print(self.response)
        if self.response['ResponseMetadata']['HTTPStatusCode'] == 200:
            return {}
        else:
            return {}
    except Exception as e:
        print(e)
        print('in processed_records_logging')
        return {}

The third diagram shows that when the data is being added to the Dynamo Table from S3 and note that the CreatedAt date is added to the dictionary to be loaded into the DynamoDB Log Table:

<< SELF DATA>>  {'CogId': 'e52119a733a0d60969564920187ef155d62de303', 'Month': '05', 'Year': '2022', 'Day': '07', 'LinkingCogId': '96cffaab877997d4a8be1b50df2c65fc4fac51ae', 'Action': 'Create', 'Object': 'Task', 'Id': '00T75000003serBEAQ', 'NewInformation': {'Company': 'Consolidated Supplies LLC', 'BDM_Sender_Last_Name__c': 'Patrick', 'Email': 'loresloan@mailinator.com', 'BDM_Sender_Email__c': 'tara.patrick@conhover.com.invalid', 'FirstName': 'Loretta', 'PostalCode': '32399', ' Power_Usage__c': 'Under $5,000 / Month', 'Campaign_ID__c': '7014N000001TMORQA4', 'LastName': 'Sloan', 'BDM_Sender_First_Name__c': 'Tara', 'MQP_Type__c': 'SMB Shopping Site', 'Designated_Owner__c': '005410000032u2MAAQ', 'OwnerId': '005410000032u2MAAQ'}, 'Result': 'Pass', 'CreatedAt': '2022-05-07 02:10:39.426901', 'ExternalId': '-'}

Finally, the following code snippet shows the error that occurs:

{'CogId': 'e52119a733a0d60969564920187ef155d62de303', 'Month': '05', 'Year': '2022', 'Day': '07', 'LinkingCogId': '96cffaab877997d4a8be1b50df2c65fc4fac51ae', 'Action': 'Create', 'Object': 'Task', 'Id': '00T75000003serBEAQ', 'NewInformation': {'Company': 'Consolidated Supplies LLC', 'BDM_Sender_Last_Name__c': 'Patrick', 'Email': 'loresloan@mailinator.com', 'BDM_Sender_Email__c': 'tara.patrick@conhover.com.invalid', 'FirstName': 'Loretta', 'PostalCode': '32399', ' Power_Usage__c': 'Under $5,000 / Month', 'Campaign_ID__c': '7014N000001TMORQA4', 'LastName': 'Sloan', 'BDM_Sender_First_Name__c': 'Tara', 'MQP_Type__c': 'SMB Shopping Site', 'Designated_Owner__c': '005410000032u2MAAQ', 'OwnerId': '005410000032u2MAAQ'}, 'Result': 'Pass', 'CreatedAt': '2022-05-07 02:10:39.426901', 'ExternalId': '-'}

2022-05-06T21:10:39.630-05:00

An error occurred (ValidationException) when calling the PutItem operation: One or more parameter values were invalid: Missing the key CreatedAt in the item

Advertisement

Answer

Wow what an oversight!! I finally came back to this project and discovered that within the Overview tab (on the AWS DynamoDB Service page), the Table definition’s Sort Key attribute (that’s underneath General Information section in The Dynamo > Tables breadcrumb) had an extra space accidentally appended after the Sort Key name! It’s no wonder my code wasn’t able to find that Sort key to do a Dynamo putItem() to the table. After the update, everything is running smoothly without exception and the process log is being written to just fine!

Advertisement