Skip to content

Instantly share code, notes, and snippets.

@cpliakas
Created November 13, 2014 21:58
Show Gist options
  • Save cpliakas/b81f2fbf49e7ae7a2db2 to your computer and use it in GitHub Desktop.
Save cpliakas/b81f2fbf49e7ae7a2db2 to your computer and use it in GitHub Desktop.
Using Goamz to put an item in DynamoDB
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