I was trying to remember how best to detect when a GetItem call to DynamoDB returns no values. That is, when there’s no item with that key in the table. This is in a project that is using v2 of the Go AWS SDK.

After poking through some old code that did this, it looks like the way to do so is to check that the returned Item field is nil:

out, err := p.client.GetItem(ctx, &dynamodb.GetItemInput{
    Key:       key,
    TableName: tableName,
})
if err != nil {
    // Error getting the item
    return nil, err
} else if out.Item == nil {
    // No item found
    return nil, nil
}

// Do the thing with out.Item

Ok, I can live with this approach. I’m kinda happy that I don’t need to check the error message, since doing so using the Go AWS SDK is a bit of a pain.