func GetItemFromDynamoDb(svc *dynamodb.DynamoDB, productId string) string { params := &dynamodb.GetItemInput{ Key: map[string]*dynamodb.AttributeValue{ // Required "productId": { // Required S: aws.String(productId), }, // More values... }, TableName: aws.String("ProductRecommendation"), // Required AttributesToGet: []*string{ aws.String("boughtTogether"), // Required // More values... }, ConsistentRead: aws.Bool(true), /* ExpressionAttributeNames: map[string]*string{ "Key": aws.String("AttributeName"), // Required // More values... }, ProjectionExpression: aws.String("ProjectionExpression"), ReturnConsumedCapacity: aws.String("ReturnConsumedCapacity"), */ } resp, err := svc.GetItem(params) if err != nil { // Print the error, cast err to awserr.Error to get the Code and // Message from an error. glog.Errorln(err.Error()) return "failed to query DynamoDb" } // Pretty-print the response data. return *resp.Item["boughtTogether"].S }
func getRecord(svc *dynamodb.DynamoDB, tableName string, key string) { params := &dynamodb.GetItemInput{ Key: map[string]*dynamodb.AttributeValue{ "key": { S: aws.String(key), }, }, TableName: aws.String(tableName), } _, err := svc.GetItem(params) if err != nil { fmt.Println(err.Error()) return } }
func retrieveItem(db *dynamodb.DynamoDB) error { var _, err = db.GetItem(getItemInput()) return err }