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

API Trace View

Struggling with slow API calls? 🕒

Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (0)

Billboard image

Deploy and scale your apps on AWS and GCP with a world class developer experience

Coherence makes it easy to set up and maintain cloud infrastructure. Harness the extensibility, compliance and cost efficiency of the cloud.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay