Skip to content

Instantly share code, notes, and snippets.

@mpfund
Created February 13, 2015 13:13
Show Gist options
  • Save mpfund/c3d39ca07d04c36cb2f3 to your computer and use it in GitHub Desktop.
Save mpfund/c3d39ca07d04c36cb2f3 to your computer and use it in GitHub Desktop.
Golang gomaz aws, dynamodb PutItem
package main
import (
"fmt"
"github.com/AdRoll/goamz/aws"
"github.com/AdRoll/goamz/dynamodb"
"log"
"strings"
)
func main() {
auth, _ := aws.EnvAuth()
nv := aws.NeverRetryPolicy{}
ddbs := dynamodb.Server{auth, aws.USEast, nv}
response, err := ddbs.ListTables()
pkattr := dynamodb.NewStringAttribute("Url", "")
pk := dynamodb.PrimaryKey{pkattr, nil}
table := dynamodb.Table{&ddbs, "urls", pk}
k := dynamodb.NewStringAttribute("Test", "test")
ok, err := table.PutItem("http://google.com", "", []dynamodb.Attribute{*k})
fmt.Println(ok)
if err != nil {
log.Fatal(err.Error())
}
fmt.Printf("The tablenames are %s!", strings.Join(response, ", "))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment