Query DynamoDB ISO-8601 Date index with less than condition

249 views
Skip to first unread message

Michael

unread,
Mar 18, 2017, 7:06:12 PM3/18/17
to boto-users

I have a DynamoDB Index storing a date in iso-8601 format, [i.e. '2017-03-17']. I'd like to query the Index for dates less than a certain date. [i.e datetime.now() - 30 days].


I believe this is support from looking at Amazon's API docs. I seem to be missing something with the boto3 syntax.


I am using the resource and not the client in boto3.


I know I can use epoch but would like to use the ISO format for readability.


Here is the test code I have.


import boto3
from boto3.dynamodb.conditions import Key, Attr

ddb = boto3.resource('dynamodb')
_table = ddb.Table('TableWithDateIndex')

response2 = _table.query(
    IndexName='DeleteDate-index',
    KeyConditionExpression=Key('IndexDate').lt('2017-04-17')
)

print response2['Items']



Fails with:

botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the Query operation: Query key condition not supported

Reply all
Reply to author
Forward
0 new messages