Skip to content

Instantly share code, notes, and snippets.

@owulveryck
Created March 20, 2017 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save owulveryck/b47bb33223ab1e594f845e8014a0de64 to your computer and use it in GitHub Desktop.
Save owulveryck/b47bb33223ab1e594f845e8014a0de64 to your computer and use it in GitHub Desktop.
Simple Query to Dynamodb
package main
import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/aws/aws-sdk-go/service/dynamodb/dynamodbattribute"
"log"
)
func main() {
fmt.Println("vim-go")
var svc *dynamodb.DynamoDB
params := &dynamodb.QueryInput{
TableName: aws.String("TableName"), // Required
ConsistentRead: aws.Bool(true),
KeyConditions: map[string]*dynamodb.Condition{
"PartitionKey": { // Required
ComparisonOperator: aws.String("EQ"), // Required
AttributeValueList: []*dynamodb.AttributeValue{
{ // Required
S: aws.String("thisvalue"),
},
},
},
},
}
resp, err := svc.Query(params)
if err != nil {
fmt.Println(err.Error())
return
}
for _, item := range resp.Items {
var res map[string]interface{}
err = dynamodbattribute.UnmarshalMap(item, &res)
if err != nil {
log.Println(err)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment