呼叫PutItem操作时发生错误(验证Exception):一个或多个参数值无效:缺少键创建的键

发布于 2025-01-26 21:27:33 字数 4793 浏览 5 评论 0原文

帮助,我完全感到困惑,为什么我会遇到此错误,这表明当putitem()调用putitem()时缺少Createat字段。我将电子邮件摄取到S3存储桶中,然后从S3中取出并加载到Dynamo日志表中。完成后,将记录上传到Salesforce作为潜在客户记录。上传到Salesforce的工作正常,但是一路上我在写入Dynamo日志表时会遇到此错误。

我使用AWS控制台创建我的DynamoDB日志表来定义 分区密钥(cogid)和排序键(创建)

”在此处输入图像说明”

然后,我使用以下python函数代码添加我的数据 - self.data-使用PUT项目函数到DynamoDblog表。数据 包括创建的键及其值self。现在包含 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 {}

第三个图显示,当数据添加到 来自S3的Dynamo表,请注意,创建日期已添加到 将字典加载到DynamoDB日志表中:

<< 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': '[email protected]', 'BDM_Sender_Email__c': '[email protected]', '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': '-'}

最后,以下代码段显示了发生的错误:

{'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': '[email protected]', 'BDM_Sender_Email__c': '[email protected]', '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

调用PutItem操作时发生错误(验证Exception):一个或多个参数值无效:在项目中丢失了键创建的键

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': '[email protected]', 'BDM_Sender_Email__c': '[email protected]', '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': '[email protected]', 'BDM_Sender_Email__c': '[email protected]', '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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

大海や 2025-02-02 21:27:33

哇,真是一个监督!我终于回到了这个项目,
在“概述”选项卡(AWS DynamoDB服务页面上)中发现,
表定义的排序关键属性(这在一般信息下
Dynamo&gt;桌子面包屑)在排序钥匙名称之后,意外附加了一个额外的空间!难怪我的代码不是
能够找到该排序键,以在表上执行Dynamo PutItem()。更新后,一切都在顺利运行,无一例外地运行,并且过程日志被写成很好!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文