【问题标题】:DynamoDB get_item "The provided key element does not match the schema"DynamoDB get_item "提供的关键元素与架构不匹配"
【发布时间】:2021-08-26 17:07:36
【问题描述】:

我正在尝试通过我们的 Ruby on Rails 应用程序 dr-recommends 使用 https://github.com/aws/aws-sdk-ruby/blob/0465bfacbf87e6bc78c38191961ed860413d85cd/gems/aws-sdk-dynamodb/lib/aws-sdk-dynamodb/table.rb#L697 实现 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

【问题讨论】:

标签: amazon-dynamodb amazon-cloudformation aws-cli


【解决方案1】:

GetItem() 要求您使用主键。

您需要同时指定哈希(又名分区)和排序键。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-14
    • 1970-01-01
    • 1970-01-01
    • 2016-07-30
    相关资源
    最近更新 更多