5

I need to scan my table in dynamodb using filtering. I found many examples in internet but when I try use them I have the same error all the time.

filter := expression.Name("CreatedDate").LessThan(expression.Value(time.Now().UTC()))
expr, err := expression.NewBuilder().WithFilter(filter).Build()
if err != nil {
    panic(err)
}
out, err := svc.Scan(context.TODO(), &dynamodb.ScanInput{
    TableName:                 aws.String(tableName),
    FilterExpression:          expr.Filter(),
    ExpressionAttributeNames:  expr.Names(),
    ExpressionAttributeValues: expr.Values(),
})
if err != nil {
    panic(err)
}

On expr.Names() and expr.Values() I got error

Cannot use 'expr.Names()' (type map[string]*string) as the type map[string]string

Thank you in advance!

1 Answer 1

4
+50

You did not specify if it was a compilation error or it is shown in the panic.

Anway, the expr.Names() expr.Values() would be map[string]*string in case of usage expression from aws-sdk-go except aws-sdk-go-v2.

Fix

Update your imports from

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
"github.com/aws/aws-sdk-go/service/dynamodb/expression"

to something like below

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/feature/dynamodb/expression"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. They moved expression from service to feature... That's why I didn't see that and used v1.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.