Tech Note
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Detecting When GetItem On DynamoDB Returns Nothing

The best way to detect when a GetItem call to DynamoDB returns no values 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