0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【aws-sdk-dynamodb】Aws::DynamoDB::Errors::ValidationException The provided key element does not match the schema【ruby】

Last updated at Posted at 2022-06-08

環境

- OS: macOS Big Sur 11.5.2
- ruby: 2.7.1

問題

# clientオブジェクトを用意
client = Aws::DynamoDB::Client.new(
  access_key_id: ENV['AWS_ACCESS_KEY_ID'],
  secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
  region: ENV['AWS_REGION']
)

# 特定のカラムの値を更新
client.update_item({
  table_name: "test_table",
  key: {Id: 1},
  update_expression: "SET #{column} = :val",
  expression_attribute_values: {':val' => value }
})

上記を実行すると、以下のエラーが発生

Aws::DynamoDB::Errors::ValidationException 
The provided key element does not match the schema

原因

プライマリーキー名のタイポだった
【正】 id
【誤】 Id

client.update_item({
  table_name: "test_table",
  key: {id: 1},  # Id => id
  update_expression: "SET #{"foo"} = :val",
  expression_attribute_values: {':val' => "bar" }
})
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?