I'm trying save JSON objects as such in dynamodb ,using newly added support for JSON type(my understanding is JSON type is basically maps+lists) so that I can query and modify nested JSON documents.
I couldn't find any golang package for dynamodb with newly added data types support.
Any suggestion on this please ?
The SDK documentation around this is a little vague, I found this .NET: Document Model helpful.
The newly amazon-backed Golang API, which includes DynamoDB, is here: https://github.com/awslabs/aws-sdk-go
To put JSON in aws-dynamodb we first need to iterate through each attribute of JSON struct and convert it to dynamodb.AttributeValue in the following manner:
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)
}