Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble getting a dynamodb scan to work with boto

I'm using boto to access a dynamodb table. Everything was going well until I tried to perform a scan operation.

I've tried a couple of syntaxes I've found after repeated searches of The Internet, but no luck:

def scanAssets(self, asset):
    results = self.table.scan({('asset', 'EQ', asset)})
         -or-
    results = self.table.scan(scan_filter={'asset':boto.dynamodb.condition.EQ(asset)})

The attribute I'm scanning for is called 'asset', and asset is a string.

The odd thing is the table.scan call always ends up going through this function:

def dynamize_scan_filter(self, scan_filter):
    """
    Convert a layer2 scan_filter parameter into the
    structure required by Layer1.
    """
    d = None
    if scan_filter:
        d = {}
        for attr_name in scan_filter:
            condition = scan_filter[attr_name]
            d[attr_name] = condition.to_dict()
    return d

I'm not a python expert, but I don't see how this would work. I.e. what kind of structure would scan_filter have to be to get through this code?

Again, maybe I'm just calling it wrong. Any suggestions?

like image 820
Jim B. Avatar asked Dec 05 '25 14:12

Jim B.


1 Answers

OK, looks like I had an import problem. Simply using:

import boto

and specifying boto.dynamodb.condition doesn't cut it. I had to add:

import dynamodb.condition

to get the condition type to get picked up. My now working code is:

results = self.table.scan(scan_filter={'asset': dynamodb.condition.EQ(asset)})

Not that I completely understand why, but it's working for me now. :-)

like image 56
Jim B. Avatar answered Dec 09 '25 23:12

Jim B.