DEV Community

Abhishek Gupta for AWS

Posted on • Originally published at community.aws

2

[20 Days of DynamoDB] Day 13 - Using the DynamoDB expression package to build Condition expressions

Posted: 25/Jan/2024

Thanks to the expression package in the AWS Go SDK for DynamoDB, you can programmatically build Condition expressions and use them with write operations. Here is an example with the DeleteItem API:

    conditionExpressionBuilder := expression.Name("inactive_days").GreaterThanEqual(expression.Value(20))
    conditionExpression, _ := expression.NewBuilder().WithCondition(conditionExpressionBuilder).Build()

    _, err := client.DeleteItem(context.Background(), &dynamodb.DeleteItemInput{
        TableName: aws.String(tableName),
        Key: map[string]types.AttributeValue{
            "email": &types.AttributeValueMemberS{Value: email},
        },
        ConditionExpression:       conditionExpression.Condition(),
        ExpressionAttributeNames:  conditionExpression.Names(),
        ExpressionAttributeValues: conditionExpression.Values(),
    })
Enter fullscreen mode Exit fullscreen mode

Recommended reading - WithCondition method in the 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)

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