2017-03-13 16 views
8

से एक आइटम हो रही त्रुटि "प्रदान की प्रमुख तत्व स्कीमा से मेल नहीं खाता" इस तालिका में विभाजन enter image description hereजब DynamoDB

की स्थापना तालिका सामग्री 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

आपकी तालिका स्कीमा में हैश कुंजी और विभाजन कुंजी दोनों परिभाषित हैं। DynamoDB GetItem का उपयोग करते समय आप उन दोनों को प्रदान करनी चाहिए, यहाँ, 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.

से एक अंश तो अपने उदाहरण दिया है यहाँ की तरह दिखना चाहिए कैसे get_item मानकों है:

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

एक अन्य बात यह है कि काम करता है नीचे दिया गया निम्न कोड है:

result = table.query(
     KeyConditionExpression=Key('userId').eq('user2873') 
    ) 
संबंधित मुद्दे