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.

preguntada hace 2 años4840 visualizaciones
1 Respuesta
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
respondido hace 2 años

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas