Created
November 13, 2014 21:58
-
-
Save cpliakas/b81f2fbf49e7ae7a2db2 to your computer and use it in GitHub Desktop.
Using Goamz to put an item in DynamoDB
This file contains 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/crowdmob/goamz/aws" | |
"github.com/crowdmob/goamz/dynamodb" | |
) | |
const ( | |
AWS_ACCESS_KEY string = "AAAAAAAAAAAAAAAAAAAA" | |
AWS_SECRET_KEY string = "aaa/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | |
DYNAMODB_TABLE_NAME string = "mytable.example.com" | |
) | |
func main() { | |
auth := &aws.Auth{AccessKey: AWS_ACCESS_KEY, SecretKey: AWS_SECRET_KEY} | |
db := dynamodb.New(*auth, aws.USEast) | |
attribute := &dynamodb.Attribute{ | |
Type: dynamodb.TYPE_STRING, | |
Name: "username", | |
} | |
primaryKey := &dynamodb.PrimaryKey{KeyAttribute: attribute} | |
table := db.NewTable(DYNAMODB_TABLE_NAME, *primaryKey) | |
attributes := make([]dynamodb.Attribute, 1) | |
attributes[0] = *dynamodb.NewStringAttribute("realName", "Chris Pliakas") | |
_, err := table.PutItem("cpliakas", "", attributes) | |
if err != nil { | |
fmt.Println(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment