Ruby DynamoDB get_item 查询因 ValidationException 而失败

Ruby DynamoDB get_item query failing with ValidationException

我正在尝试使用 Ruby api.

查询 DynamoDB
query = {
    table_name : TABLE_NAME,
    key : {
        'foo:bar'.to_sym => {:s => 'value'}
    }  
}
x = @ddb_client.get_item(query) # ERROR on this line.

错误是。

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

我有一种感觉,这是因为 table 的哈希键被命名为 foo:bar,名称中有一个冒号。因此我无法使用 key : { :index => "value"}

我尝试了以下密钥值。

仍然出现同样的错误。

原来我在查询中遗漏了范围键。

我们的主索引由散列键和范围键组成。

将查询更改为后。

query = {
    table_name : TABLE_NAME,
    key : {
        'foo:bar'.to_sym => {:s => 'value'}
        'range_key' => {:s => 'value'}
    }  
}

一切正常。