2017-06-02 41 views
0

這是我的表看起來像:無效KeyConditionExpression在boto3 dynamodb查詢

enter image description here

toHash是我的主分區鍵和timestamp是排序鍵。

所以,當我執行此代碼[爲了得到反向排序timestamp列表]:從boto3.dynamodb.conditions

進口boto3 導入密鑰,的Attr

client = boto3.client('dynamodb') 
response = client.query(
    TableName='logs', 
    Limit=1, 
    ScanIndexForward=False, 
    KeyConditionExpression="toHash = :X", 
) 

我得到的以下錯誤:

botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the Query operation: Invalid KeyConditionExpression: An expression attribute value used in expression is not defined; attribute value: :X 

我在這裏做錯了什麼? 爲什麼X被認爲是一個有效的屬性值?在查詢X`` - :

+0

您需要提供一個''ExpressionAttributeValues''子句查詢爲''提供值。 – garnaat

回答

0

添加ExpressionAttributeValues下面提到

response = client.query(
    TableName='logs', 
    Limit=1, 
    ScanIndexForward=False, 
    KeyConditionExpression="toHash = :X", 
    ExpressionAttributeValues={":X" : {"S" : "somevalue"}} 
)