-2

I have a table stored in dynamoDB which exemplary dictionary is the following:

 {event': 'A',
  'timestamp': '2017-10-15 16:20:47,009',
  'message': 'AAA'},
 {event': 'B',
  'timestamp': '2018-10-15 16:20:47,009',
  'message': 'BBB'},
 {event': 'A',
  'timestamp': '2019-10-15 16:20:47,009',
  'message': 'BBB'},
 {event': 'B',
  'timestamp': '2020-10-15 16:20:47,009',
  'message': 'AAA'},

I would like to extract only those dictionaries that happened after 2018-10-15 00:00:00

I used the following code to load the table:

import boto3
client = boto3.client("dynamodb", region_name="eu-central-1")
session = boto3.Session(profile_name="myprofile")
resource = session.resource("dynamodb", region_name="eu-central-1")
table = resource.Table("mytable")

I read that this relatively easy task is not so easy to perform when considering dynamodb, for which the global secondary index has to be created.I tried plenty of stuff but everything failed, do you have any idea what can I do to query over timestamp in the simplest manner? I would highly like to avoid using GSI, because for me its very complicated stuff for very easy task to perform.

John
  • 1,849
  • 2
  • 13
  • 23

1 Answers1

0

Apparently I found the solution which is very simple but I couldn't find it anywhere on internet.

The solution is:

from boto3.dynamodb.conditions import Key


table.query(KeyConditionExpression=Key("event").eq("A") & Key("timestamp").gt("2018-10-15 00:00:00"))
John
  • 1,849
  • 2
  • 13
  • 23