1

I'm trying to implement a DynamoDB get_item call using https://github.com/aws/aws-sdk-ruby/blob/0465bfacbf87e6bc78c38191961ed860413d85cd/gems/aws-sdk-dynamodb/lib/aws-sdk-dynamodb/table.rb#L697 via our Ruby on Rails app, dr-recommends.

From reviewing this DynamoDB CloudFormation stack that I wrote, I expect the following get_item call to work, so I'm a little lost as to how to proceed.

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'

Do you see anything here that would explain why the following call might not work?

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
Patrick Taylor
  • 112
  • 2
  • 11
  • 1
    Does this answer your question? [AWS API Gateway DynamoDB GetItem without sort key?](https://stackoverflow.com/questions/50599256/aws-api-gateway-dynamodb-getitem-without-sort-key) – Charles Jun 09 '21 at 17:20

1 Answers1

2

GetItem() requires you to use the primary key.

You'll need to specify both hash(aka partition) and sort keys.

Charles
  • 21,637
  • 1
  • 20
  • 44