Search code examples
amazon-dynamodbaws-sdk-go

How do I use begins_with in the Amazon DynamoDB SDK for Go


I'm doing a query against DynamoDB using the AWS Go SDK to get all items with a given partition key and a sort key that begins with a string (an email address in this case). Here's the QueryInput:

input := &dynamodb.QueryInput{
    KeyConditionExpression: aws.String("PartK = :hashKey and SortK begins_with :rangeKey"),
    ExpressionAttributeValues: map[string]*dynamodb.AttributeValue {
        ":hashKey":  &dynamodb.AttributeValue{S: aws.String(partk[0])},
        ":rangeKey": &dynamodb.AttributeValue{S: aws.String(sortk[0])},
    },

    TableName: aws.String("my-table"),
}

This fails with this error:

Invalid KeyConditionExpression: Syntax error; token: "begins_with", near: "SortK begins_with :rangeKey"

Apparently "begins_with" isn't the right operator for the Go SDK. Does someone have a code sample that shows how to use the begins_with operator with the Go SDK?

A more general question. We are just getting started moving from an RDS instance to DynamoDB. I've noticed that there aren't many code examples of the AWS Go SDK for DynamoDB. I've also found the AWS docs to be nearly useless and the API itself to be convoluted and poorly abstracted. Maybe that is why there are so few code examples available.

Is there another SDK available for DynamoDB and Go? A good commercial SDK would be OK because the AWS SDK looks like it will be a productivity killer.


Solution

  • Here's the syntax that works:

    "PartK = :hashKey and begins_with(SortK, :rangeKey)"
    

    I'm still interested in hearing about alternatives to the AWS Go SDK for DynamoDB.