Dynamo DB Pages

Posted on May 25, 2021

Dynamo code snippet

Recently got burned because we needed to do a recursive paging through dynamo

var listOfThings []Whatever

err := store.ScanPages(input,
    func (page *dynamodb.ScanOutput, lastPage bool) bool {
        for _, item := range page.Items {
            var whateva Whatever
            if val, ok := item["jval"]; ok {
                err := json.Unmarshal([]byte(*val.S), &whateva)
                if err != nil {
                    return true // its like continue
                }
                listOfThings = append(listOfThings, whateva)
            }
        }
    return !lastPage
})
if err != nil {
    t.Fail()
}
https://bneil.me/notes/dynamodb_pages/