Jan. 30, 2024, 4:12 a.m. | Abhishek Gupta

DEV Community dev.to

Posted: 30/Jan/2024


You can use expression package in the AWS Go SDK for DynamoDB to programmatically build key condition and filter expressions and use them with Query API.


Here is an example that queries for a specific thread based on the forum name (partition key) and subject (sort key):



    keyConditionBuilder := expression.Key("ForumName").Equal(expression.Value("Amazon DynamoDB"))
filterExpressionBuilder := expression.Name("Views").GreaterThanEqual(expression.Value(3))

expr, _ := expression.NewBuilder().
WithKeyCondition(keyConditionBuilder).
WithFilter(filterExpressionBuilder).
Build()

_, err := client.Query(context.Background(), &dynamodb.QueryInput{
TableName: aws.String("Thread"),
KeyConditionExpression: expr.KeyCondition(),
FilterExpression: expr.Filter(),
ExpressionAttributeNames: expr.Names(),
ExpressionAttributeValues: expr.Values(),
})


Recommended …

api aws build can cloud database dynamodb expressions filter key package query sdk serverless

CyberSOC Technical Lead

@ Integrity360 | Sandyford, Dublin, Ireland

Cyber Security Strategy Consultant

@ Capco | New York City

Cyber Security Senior Consultant

@ Capco | Chicago, IL

Sr. Product Manager

@ MixMode | Remote, US

Corporate Intern - Information Security (Year Round)

@ Associated Bank | US WI Remote

Senior Offensive Security Engineer

@ CoStar Group | US-DC Washington, DC