Golang package for dynamodb with map, list and JSON support

I am trying to store JSON objects as such in dynamodb using the new added support for JSON type (I understand JSON type is basically maps + lists) so that I can query and modify nested JSON documents.

I couldn't find a golang package for dynamodb with support for the newly added datatypes.

Any suggestion on this please?

+3


source to share


3 answers


The SDK documentation around this is a bit vague, I found this one . NET: Document Model is useful.



+1


source


The new Amazon-backed Golang API that includes DynamoDB is here: https://github.com/awslabs/aws-sdk-go



+1


source


To put JSON in aws-dynamodb, you first need to iterate over each attribute of the JSON structure and convert it to dynamodb.AttributeValue as follows:

func (e *DB) saveToDynamodb(data map[string]interface{}){
var vv=make(map[string]*dynamodb.AttributeValue)

for k,v:=range data{
    x:=(v.(string))  //assert type as required
    xx:=&(x)
    vv[k]=&dynamodb.AttributeValue{S: xx,}
}
//s:=data["asset_id"].(string)
params := &dynamodb.PutItemInput{
    Item: vv,
    TableName: aws.String("Asset_Data"), // Required
}
resp, err := e.dynamodb.PutItem(params)

if err != nil {
    // Print the error, cast err to awserr.Error to get the Code and
    // Message from an error.
    fmt.Println(err.Error())
    return
}

// Pretty-print the response data.
fmt.Println(resp)
}

      

0


source







All Articles