DEV Community

Abhishek Gupta for AWS

Posted on • Originally published at community.aws

2 1

[20 Days of DynamoDB] Day 12 - Using the DynamoDB expression package to build Projection expressions

Posted: 23/Jan/2024

The expression package in the AWS Go SDK for DynamoDB provides a fluent builder API with types and functions to create expression strings programmatically along with corresponding expression attribute names and values.

Here is an example of how you would build a Projection Expression and use it with the GetItem API:

    projectionBuilder := expression.NamesList(expression.Name("first_name"), expression.Name("last_name"))
    projectionExpression, _ := expression.NewBuilder().WithProjection(projectionBuilder).Build()

    _, err := client.GetItem(context.Background(), &dynamodb.GetItemInput{
        TableName: aws.String("customer"),
        Key: map[string]types.AttributeValue{
            "email": &types.AttributeValueMemberS{Value: "c1@foo.com"},
        },
        ProjectionExpression:     projectionExpression.Projection(),
        ExpressionAttributeNames: projectionExpression.Names(),
    })
Enter fullscreen mode Exit fullscreen mode

Recommended reading - expression package API docs

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Postgres on Neon - Get the Free Plan

No credit card required. The database you love, on a serverless platform designed to help you build faster.

Get Postgres on Neon

👋 Kindness is contagious

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

Okay