DEV Community

Abhishek Gupta for AWS

Posted on • Originally published at community.aws

3 1 1 1 1

[20 Days of DynamoDB] Day 2 - GetItem add-on benefits

Posted: 9/Jan/2024

Did you know that the DynamoDB GetItem operation also gives you the ability to:

  • Switch to strongly consistent read (eventually consistent being the default)
  • Use a projection expression to return only some of the attributes
  • Return the consumed Read Capacity Units (RCU)

Here is an example (DynamoDB Go SDK):

    resp, err := client.GetItem(context.Background(), &dynamodb.GetItemInput{
        TableName: aws.String(tableName),
        Key: map[string]types.AttributeValue{
            //email - partition key
            "email": &types.AttributeValueMemberS{Value: email},
        },
        ConsistentRead:         aws.Bool(true),
        ProjectionExpression:   aws.String("first_name, last_name"),
        ReturnConsumedCapacity: types.ReturnConsumedCapacityTotal,
    })
Enter fullscreen mode Exit fullscreen mode

Recommended reading:

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay