问题描述
我正在尝试通过我们的 Ruby on Rails 应用程序 https://github.com/aws/aws-sdk-ruby/blob/0465bfacbf87e6bc78c38191961ed860413d85cd/gems/aws-sdk-dynamodb/lib/aws-sdk-dynamodb/table.rb#L697 使用 dr-recommends 实现 DynamoDB get_item
调用。
通过查看我编写的这个 DynamoDB CloudFormation 堆栈,我希望以下 get_item
调用能够正常工作,因此我对如何继续操作有点迷茫。
Type: 'AWS::DynamoDB::Table'
Properties:
AttributeDeFinitions:
- AttributeName: 'pk'
AttributeType: 'S'
- AttributeName: 'sk'
AttributeType: 'S'
KeySchema:
- KeyType: 'HASH'
AttributeName: 'pk'
- KeyType: 'RANGE'
AttributeName: 'sk'
BillingMode: 'PAY_PER_REQUEST'
您是否在这里看到任何可以解释为什么以下调用可能不起作用的内容?
aws dynamodb get-item --table-name actual-table-name --key "{\"pk\":{\"S\":\"77119f89-d5bc-4662-91bb-f3e81e1d9b21\"}}" --projection-expression sk
# An error occurred (ValidationException) when calling the GetItem operation: The provided key element does not match the schema
解决方法
GetItem() 要求您使用主键。
您需要同时指定哈希(又名分区)和排序键。