Created
March 20, 2017 10:14
-
-
Save owulveryck/b47bb33223ab1e594f845e8014a0de64 to your computer and use it in GitHub Desktop.
Simple Query to Dynamodb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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