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')
Optionally, you can provide a sort key attribute and use a comparison operator to refine the search results. For more information on how to use Query , such as the request syntax, response parameters, and additional examples, see Query in the Amazon DynamoDB API Reference.
Step 1 − Import boto3 and botocore exceptions to handle exceptions. Step 2 − database_name and table_name is the mandatory parameter. It fetches the definition of given table. Step 3 − Create an AWS session using boto3 library.
Connecting AWS resources to the python environment requires a boto3 package. Creating a dynamo DB client is a connection instance that lets us connect with our dynamo DB service. We need to specify region_name , aws_access_key_id , aws_secret_access_key in order to connect with our dynamoDb service.
Please change the ExpressionAttributeValues as mentioned below.
ExpressionAttributeValues={':cihan': 'cihan'}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With