Scylla Alternator interface + AWS Golang SDK

I have setup a table through the Scylla alternator interface like so (through python script):

table_definition = dynamodb.create_table(
    TableName='display_name_tagging',
    KeySchema=[
        {
            'AttributeName': 'a_party',
            'KeyType': 'HASH'  # Partition Key
        },
        {
            'AttributeName': 'display_name_tag',
            'KeyType': 'RANGE'  # Sort Key
        }
    ],
    AttributeDefinitions=[
        {
            'AttributeName': 'a_party',
            'AttributeType': 'N'  # number data type
        },
        {
            'AttributeName': 'display_name_tag',
            'AttributeType': 'S'  # string data type
        }
    ],
    ProvisionedThroughput={
        'ReadCapacityUnits': 10,
        'WriteCapacityUnits': 10
    }
)

Now using Golang and AWS SDK I am connecting to that keyspace and trying to write a record into a table:

func insertRecord(db *dynamodb.DynamoDB) {
	item := Item{a_party: 1234567890, display_name_tag: "Mike Test"}
	nr, mErr := dynamodbattribute.MarshalMap(item)
	if mErr != nil {
		llog.Fatalf("Got error marshalling map: %s", mErr)
	}
	_, err := db.PutItem(
		&dynamodb.PutItemInput{
			Item:      nr,
			TableName: aws.String("display_name_tagging"),
		},
	)
	if err != nil {
		log.Fatalf("Got error calling insertRecord: %s", err)
	}

	fmt.Println("Inserted into table display_name_tagging")
}

but when I run my program, I get this error:

ValidationException: Key column a_party not found

Doing search online has not produced any results. Any help would be appreciated.

I tried to do the same in Python (I’m not familiar with Go), and it worked just fine:

table.put_item(Item={'a_party': 1234567890, 'display_name_tag': 'Mike Test'})

The error you got is exactly the kind of error you get when the item does not have an a_party field, for example:

table.put_item(Item={'xyz': 1234567890, 'display_name_tag': 'Mike Test'})

Gives you, as expected (because the item is missing the key column a_party):

An error occurred (ValidationException) when calling the PutItem operation: Key column a_party not found.

So I can only guess that the item you passed to PutItem has the wrong format. I’m not familiar with the Go SDK, but did you really need to call that MarshalMap thing on the item instead of just passing “item” (in the Python SDK, for example, this conversion is done automatically for you)? Can you try just passing “item”?
And if it’s necessary, did you use the correct way? Can you please print “nr” after the marshalling and show me what it looks like?

Don’t see the full code but looks like a_party is a private field of Item so MarshalMap would produce empty map. Since a_party is a key you can’t put an item without it as nyh wrote above.

BTW when writing new project aws advises to use golang aws sdk v2.

1 Like