当我尝试从表中获取项目时,它会打印此错误
botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the GetItem operation: The provided key element does not match the schema
这是我的代码
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('testDynamodb')
response = table.get_item(Key={'userId': "user2873"})
item = response['Item']
print(item)
有什么想法吗?谢谢。
最佳答案
您的表架构同时定义了哈希键和排序键。使用 DynamoDB GetItem 时,您必须同时提供它们,这里是 documentation 的摘录
For the primary key, you must provide all of the attributes. For example, with a simple primary key, you only need to provide a value for the partition key. For a composite primary key, you must provide values for both the partition key and the sort key.
鉴于您的示例,get_item 参数应如下所示:
response = table.get_item(Key={'userId': "user2873", 'createdAt': "1489376547"})
关于python - 从 DynamoDB 获取项目时出现 "The provided key element does not match the schema"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42757872/