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

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

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

Okay