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

How I Cut 22.3 Seconds Off an API Call with Sentry

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

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