dynamodb get_item boto3 参数验证失败

dynamodb get_item boto3 Parameter validation failed

使用 boto3 我试图在 dynamodb 中获取一个对象 table。

在此堆栈溢出之后post正确的语法是

client = boto3.client('dynamodb')

response = client.get_item(TableName='Garbage_collector_table', Key={'topic':{'S':str(my_topic)}})

http://boto3.readthedocs.io/en/latest/reference/services/dynamodb.html

我尝试了各种迭代以获得正确的语法,我当前的语法是这样的

 if event['hcpcs_codes'] != None:
        # codes must be in numerical, alphabetical order
        # multi codes should be seperated by a comma with no spaces
        client = boto3.client('dynamodb')
        payload = {
            "HCPCSCodeSet": event['hcpcs_codes']
        }
        response = client.get_item(TableName="mce-hcpcs-associations-table-dev",
                                   Key={'HCPCSCodeSet':{'S': payload}})
        print('here comes the tacos brah')
        print(response)

我不确定这东西想要什么。正确的语法是什么?

Invalid type for parameter Key.HCPCSCodeSet, value: tacoman, type: <class 'str'>, valid types: <class 'dict'>
Traceback (most recent call last):
  File "/var/task/lambdafile.py", line 18, in lambda_handler
    Key= payload)
  File "/var/task/botocore/client.py", line 415, in _api_call

dynamodb 数据库的主键名称是

Partition key
HCPCSCodeSet (String)

此代码:

        payload = {
            "HCPCSCodeSet": event['hcpcs_codes']
        }
        response = client.get_item(TableName="mce-hcpcs-associations-table-dev",
                                   Key={'HCPCSCodeSet':{'S': payload}})

最终尝试将以下内容发送到 DynamoDB:

Key={'HCPCSCodeSet':{'S': {
            "HCPCSCodeSet": event['hcpcs_codes']
        }}}

这显然是不正确的。目前还不清楚您为什么要构建 payload 对象。你可以这样做:

        response = client.get_item(TableName="mce-hcpcs-associations-table-dev",
                                   Key={'HCPCSCodeSet':{'S': event['hcpcs_codes']}})