2017-03-13 20 views
8

からアイテムを取得するときにこれは私がアイテムを取得しようとすると、テーブルの内容 enter image description hereDynamoDBの

enter image description here

を設定し、テーブルのパーティション・キーでエラー「提供重要な要素は、スキーマと一致していません」テーブルから、これは私のコードである

botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the GetItem operation: The provided key element does not match the schema

このエラーを出力

dynamodb = boto3.resource('dynamodb') 
table = dynamodb.Table('testDynamodb') 
response = table.get_item(Key={'userId': "user2873"}) 
item = response['Item'] 
print(item) 

アイデア?ありがとう。

答えて

8

テーブルスキーマには、ハッシュキーとパーティションキーの両方が定義されています。作品

response = table.get_item(Key={'userId': "user2873", 'createdAt': "1489376547"}) 
0

もうひとつ:DynamoDBのGetItem関数を使用している場合、あなたがそれらの両方を提供する必要があり、ここではここのようになりますかget_itemパラメータである、だからあなたの例を与えるdocumentation

For the primary key, you must provide all of the attributes. For example, with a simple primary key, you only need to provide a value for the partition key. For a composite primary key, you must provide values for both the partition key and the sort key.

からの抜粋です。次のコードは次のとおりです。

result = table.query(
     KeyConditionExpression=Key('userId').eq('user2873') 
    )