python getItem 上的 boto3 DynamoDB 验证错误,但架构看起来正确

python boto3 DynamoDB validation error on getItem yet schema looks correct

这是我的 dynamoDB 的方案 table

这是我请求 get_item

的方式
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')
        response = None
        try:
            response = client.get_item(TableName=os.environ['TABLE'],
                                   Key={'antecedents':{'S': str(event['hcpcs_codes'])}})
        except ValidationError as e:
            print(e)
        print('here comes the tacos brah')
        print(response)

但我收到错误:

[ERROR] ClientError: An error occurred (ValidationException) when calling the GetItem operation: The provided key element does not match the schema
Traceback (most recent call last):
  File "/var/task/lambdafile.py", line 19, in lambda_handler
    Key={'antecedents':{'S': str(event['hcpcs_codes'])}})
  File "/var/task/botocore/client.py", line 415, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/var/task/botocore/client.py", line 745, in _make_api_call
    raise error_class(parsed_response, operation_name)

并根据文档。看来我做对了

https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb.html#DynamoDB.Client.get_item

response = client.get_item(
    TableName='string',
    Key={
        'string': {
            'S': 'string',
            'N': 'string',
            'B': b'bytes',
            'SS': [
                'string',
            ],
            'NS': [
                'string',
            ],
            'BS': [
                b'bytes',
            ],
            'M': {
                'string': {'... recursive ...'}
            },
            'L': [
                {'... recursive ...'},
            ],
            'NULL': True|False,
            'BOOL': True|False
        }
    },
    AttributesToGet=[
        'string',
    ],
    ConsistentRead=True|False,
    ReturnConsumedCapacity='INDEXES'|'TOTAL'|'NONE',
    ProjectionExpression='string',
    ExpressionAttributeNames={
        'string': 'string'
    }
)

如果 table 设置了排序键,则在使用 GetItem 时必须同时提供分区键和排序键。