Jan. 24, 2024, 11:21 a.m. | Abhishek Gupta

DEV Community dev.to

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(),
})


Recommended …

api aws build builder cloud database dynamodb expressions functions names package sdk serverless strings types

SOC 2 Manager, Audit and Certification

@ Deloitte | US and CA Multiple Locations

Network Security Engineer

@ Meta | Menlo Park, CA | Remote, US

Security Engineer, Investigations - i3

@ Meta | Washington, DC

Threat Investigator- Security Analyst

@ Meta | Menlo Park, CA | Seattle, WA | Washington, DC

Security Operations Engineer II

@ Microsoft | Redmond, Washington, United States

Engineering -- Tech Risk -- Global Cyber Defense & Intelligence -- Bug Bounty -- Associate -- Dallas

@ Goldman Sachs | Dallas, Texas, United States