I need an example in Go on how to do a query on an index in dynamo db. For JavaScript I found this one: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/SQLtoNoSQL.Indexes.QueryAndScan.html
I could not find one for Go. I tried this:
// Here "user_id" is the key, and
// "user_id_index" is the secondary index
keyCondition := expression.Key("user_id").Equal(expression.Value(userId))
expr, errExpression := expression.NewBuilder().WithKeyCondition(keyCondition).WithProjection(proj).Build()
if errExpression != nil {
log.Printf("error: creating dynamo expression ", errExpression)
return listResponse, errExpression
}
params := &dynamodb.QueryInput{
ExpressionAttributeValues: expr.Values(),
ProjectionExpression: expr.Projection(),
TableName: aws.String(tableName),
IndexName: aws.String("user_id_index"),
KeyConditionExpression: expr.KeyCondition(),
}
result, errResults := svc.Query(params)
I get the following error:
error: scanning dynamo table %!(EXTRA *awserr.requestError=ValidationException:
Invalid KeyConditionExpression: An expression attribute name used in the document path is not defined;
attribute name: #0
Any link to a good tutorial would be appreciated, or code example as an answer too.