2 回答
TA贡献1847条经验 获得超11个赞
要将 JSON 放入 aws-dynamodb,我们首先需要遍历 JSON 结构的每个属性并将其转换为 dynamodb.AttributeValue,如下所示:
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)
}
- 2 回答
- 0 关注
- 185 浏览
添加回答
举报