2017-03-13 1 views
8

immer Schlüssel Dies ist die Tabellenpartition enter image description hereFehler „Der angegebene Schlüsselelement nicht das Schema überein“, wenn ein Element aus DynamoDB

den Tabelleninhalt Einstellung enter image description here

Als ich versuchte, einen Gegenstand zu erhalten aus der Tabelle, druckt er diesen Fehler

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

das ist mein Code ist

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

Irgendwelche Ideen? Vielen Dank.

Antwort

8

In Ihrem Tabellenschema sind sowohl der Hash-Schlüssel als auch der Partitionsschlüssel definiert. Wenn DynamoDB GetItem verwenden Sie beide bieten müssen, hier ist ein Auszug aus 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.

So Ihr Beispiel gegeben, hier ist, wie get_item Parameter sollte wie folgt aussehen:

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

Eine andere Sache, die funktioniert ist der folgende Code:

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