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년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠