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!
CodePudding user response:
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"