2
votes

I'm simply trying to retrieve the max value of my primary keys with a query/scan using Boto3. I'm trying to accomplish this so my program can simply increment a variable I'll set equal to the max "ID" value by 1 for the next table entry.

Screenshot of DynamoDB Table

response = table.scan(
    FilterExpression=Attr('ID'). #Here is where I'd assume a condition
)                                #is placed to find the highest value but
                                 #the Boto3 doc doesn't seem to have a 
                                 #method like 'max()' or something...

Searching around I found how to do this using the original 'boto' so I'm sure there is a way using its newer version 'boto3' but I haven't found anything yet.

Any help/guidance would be greatly appreciated! Thanks!

Boto3 Doc: http://boto3.readthedocs.io/en/latest/guide/dynamodb.html#querying-and-scanning

1

1 Answers

0
votes

I am suffering from the same issue and can't find an elegant solution. However if your primary keys are just integers you can do something like this to find the max key:

import boto3

dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table(table_name)
max_key = table.item_count