简体   繁体   中英

Modify item attribute after scan using boto3 in AWS Lambda

The goal is to scan and return all of the items in a DynamoDB table, but before the response is returned, modify a specific attribute of each specific item.

I have this completed already, but I'm curious to know if there is a more cost-effective way without looping through all the items.

Currently I'm returning a complete scan of the table and looping through each list item (found out it is not an object but a list):

    dynamodb = boto3.resource('dynamodb')
    table = dynamodb.Table('<table name>')

    response = table.scan()

    items = response['Items']

    for item in items:
        item['Thumbnail'] = 'https://s3.amazonaws.com/<s3bucket>/' + item['Thumbnail']

    return items

I doubt the solution can be resolved without looping but if there is a solution that avoids looping I'm eager to hear it!

Your cost for the loop to update the items will be measured in ms. The Dynamodb scan + network latency will take much more time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM