DynamoDB: ValidationException: ExpressionAttributeNames can only be specified when using expressions

0

I am writing some code to query Dynamo with a certain filter and I'm using the expression package in the Go sdk:

The variable project that is referred to is defined in another section of the code. Its string properties owner and name are not nil/empty.

dynamo := dynamodb.New(sess)

filt := expression.Name("projectOwner").Equal(
	expression.Value(project.owner),
).And(
	expression.Name("projectName").Equal(
		expression.Value(project.name),
	),
)

expr, err := expression.NewBuilder().WithFilter(filt).Build()
if err != nil {
       panic(err)
}

queryInput := dynamodb.QueryInput{
      KeyConditionExpression:    expr.KeyCondition(),
      ProjectionExpression:      expr.Projection(),
      ExpressionAttributeNames:  expr.Names(),
      ExpressionAttributeValues: expr.Values(),
      TableName: aws.String("projects"),
}
	
out, err := dynamo.Query(&queryInput)
if err != nil {
       panic(err)
}

I get this error:

panic: ValidationException: ExpressionAttributeNames can only be specified when using expressions

I don't know where it's from or what it means: I am using expressions.

已提问 2 年前4841 查看次数
1 回答
0

You are confusing between the syntax of Query and Scan.
When building a Query command you should use WithKeyCondition(KeyCond):

builder := expression.NewBuilder().WithKeyCondition(keyCond).WithProjection(proj)

and when building a Scan you should use WithFilter(filt):

expr, err := expression.NewBuilder().WithFilter(filt).WithProjection(proj).Build()
MLGuy
已回答 2 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则