boto3 query using KeyConditionExpression
Solution 1
Please change the ExpressionAttributeValues as mentioned below.
ExpressionAttributeValues={':cihan': 'cihan'}
Solution 2
In current versions of boto3 (1.9.128) the query mentioned in the question asked works fine, and nothing else apart from that is working now, the query mentioned below worked for me:-
dynamo_client.query(
KeyConditionExpression='campaign_id = :201906',
ExpressionAttributeValues={':201906': {'S': '201906'}}
)
tayfun
python, linux, javascript, vim, css, html, web, postgresql, memcached, mongodb
Updated on July 26, 2022Comments
-
tayfun almost 2 years
I'm having trouble understanding why below query on a DynamoDB table doesn't work:
dict_table.query(KeyConditionExpression='norm = :cihan', ExpressionAttributeValues={':cihan': {'S': 'cihan'}})
and throws this error:
ClientError: An error occurred (ValidationException) when calling the Query operation: One or more parameter values were invalid: Condition parameter type does not match schema type
while the following works:
dict_table.query(KeyConditionExpression=Key('norm').eq('cihan'))
norm
is a field with type string. I'm using boto3 v 1.4.0 and following the docs:In [43]: boto3.__version__ Out[43]: '1.4.0'
Can anyone see what's the error in the first query?
Bonus question: What's with all the tokens and the need to replace them all the time? Why can't I just say
dict_table.query(KeyConditionExpression='norm = cihan')
-
tayfun over 7 yearsThanks, that worked! But why do the Boto3 document give the following example?
{ ":avail":{"S":"Available"}, ":back":{"S":"Backordered"}, ":disc":{"S":"Discontinued"} }
See boto3.readthedocs.io/en/latest/reference/services/… -
nedned over 6 yearsI agree, the docs are misleading. They make it seem like the values of the dictionary you provide for ExpressionAttributeValues, should themselves be dictionaries with keys such as 'S', 'B', and 'N', whereas I think it's just trying to indicate that those are the possible types of the values.
-
nedned over 6 yearsOn second thoughts, it just seems incorrect. Perhaps from a previous version of the boto3 API.