I'm using https://godoc.org/github.com/aws/aws-sdk-go-v2/service/dynamodb#DynamoDB.PutItemRequest
My function looks like:
func (h dynamoHandler) save(selection DeliveryDate) (err error) {
av, err := dynamodbattribute.MarshalMap(selection)
if err != nil {
log.WithError(err).Error("failed to marshal selection")
return
}
req := h.db.PutItemRequest(&dynamodb.PutItemInput{
TableName: aws.String(h.Table),
Item: av,
})
_, err = req.Send()
if err != nil {
log.WithField("table", h.Table).WithError(err).Error("putting dynamodb")
return
}
return
}
I was under the assumption that since the partition key "wfr5a" is the same, the newer "chosen#2019-05-19T13:42:54+08:00" (a composite and sort key) should have replaced the row.
"OrderID (S)","StatusDate (S)","LastUpdated (S)"
"wfr5a","chosen#2019-05-19T13:42:54+08:00","2019-05-19T13:49:34+08:00"
"wfr5a","proposal#2019-05-19T13:42:54+08:00","2019-05-19T13:42:58+08:00"
Though as you can see, it created a new item. What am I missing to so that it just replaces the record, i.e. has only one unique row for "wfr5a"
when you have composite primary key(partition key + sort key) the combination of the two fields are unique and not the partition key.
It sounds like what you need to do is remove the sort key from the schema. That way, each item will be uniquely identified by partition key alone.
There is no API available to replace all items that have a partition key so to implement the behavior you are describing you would have to do a query-delete-put transaction to actually replace the old item with the new unless you change the schema.