I am very new to DynamoDB. I want to query all data within certain time range.
column = "timerange" is primary sort key
column = "name" is primary partition key.
I want to get all data within 2 timerange.
This is my query.
from decimal import *
from boto3.dynamodb.conditions import Key, Attr
import boto3
import time
from datetime import datetime
dynamo = boto3.resource('dynamodb')
table = dynamo.Table('tablename')
a = time.mktime(datetime.strptime('2020-03-26 14:29:10','%Y-%m-%d %H:%M:%S').timetuple())
b = time.mktime(datetime.strptime('2020-03-26 14:30:10','%Y-%m-%d %H:%M:%S').timetuple())
response = table.query(
KeyConditionExpression =
Key('timerange').between(Decimal(a), Decimal(b)))
Which gives me an error ClientError: An error occurred (ValidationException) when calling the Query operation: Query condition missed key schema element:
After searching the internet I found out that you need to have primary partition key inside your query
so I tried the Contains method from https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Condition.html
response = table.query(
KeyConditionExpression =
Key('name').contains('a', 'b') &
Key('timerange').between(Decimal(a), Decimal(b)))
Which I clearly do not understand fully.
How can I get all data within given timerange [a,b]?