Skip to content

Instantly share code, notes, and snippets.

@doncicuto
Last active January 22, 2018 14:41
Show Gist options
  • Save doncicuto/5fc7cb77f495534e68ae3072c5a9af95 to your computer and use it in GitHub Desktop.
Save doncicuto/5fc7cb77f495534e68ae3072c5a9af95 to your computer and use it in GitHub Desktop.
DynamoDB Tutorial Part 1
package main
import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/dynamodb"
)
func main() {
config := &aws.Config{
Region: aws.String("us-west-2"),
Endpoint: aws.String("http://localhost:8000"),
}
sess := session.Must(session.NewSession(config))
svc := dynamodb.New(sess)
input := &dynamodb.CreateTableInput{
AttributeDefinitions: []*dynamodb.AttributeDefinition{
{
AttributeName: aws.String("year"),
AttributeType: aws.String("N"),
},
{
AttributeName: aws.String("title"),
AttributeType: aws.String("S"),
},
},
KeySchema: []*dynamodb.KeySchemaElement{
{
AttributeName: aws.String("year"),
KeyType: aws.String("HASH"),
},
{
AttributeName: aws.String("title"),
KeyType: aws.String("RANGE"),
},
},
ProvisionedThroughput: &dynamodb.ProvisionedThroughput{
ReadCapacityUnits: aws.Int64(10),
WriteCapacityUnits: aws.Int64(10),
},
TableName: aws.String("Movies"),
}
result, err := svc.CreateTable(input)
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Println(result)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment