调用 PutItem 操作时发生错误 (ValidationException):一个或多个参数值无效:缺少键 CreatedAt

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

帮助,我完全不明白为什么我会收到此错误,指示在调用 PutItem() 时缺少 CreateAt 字段。我将电子邮件摄取到 S3 存储桶中,然后将其从 S3 中取出并加载到 Dynamo 日志中 table。完成后,记录将作为潜在客户记录上传到 Salesforce。上传到 Salesforce 工作正常,但在写入 Dynamo 日志时出现此错误 table。

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

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 ,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 ,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

调用 PutItem 操作时发生错误 (ValidationException):一个或多个参数值无效:缺少项中的键 CreatedAt

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!