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.

gefragt vor 2 Jahren4843 Aufrufe
1 Antwort
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
beantwortet vor 2 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen