This guide walks you through installing, configuring, and deploying the Go implementation of DynamORM.
For the multi-language monorepo:
- TypeScript:
ts/docs/getting-started.md - Python:
py/docs/getting-started.md
Required:
- Go 1.25 or higher
- AWS Credentials configured (or IAM role in Lambda)
- Basic understanding of DynamoDB (Primary Keys, Tables)
Recommended:
- AWS CLI installed for verification
- Docker (if using DynamoDB Local)
# Add DynamORM to your project
go get github.com/pay-theory/dynamormWhat this does:
- Downloads the library and its dependencies (including AWS SDK v2)
- Updates your
go.modandgo.sumfiles
Create a struct that represents your DynamoDB item.
package models
import "time"
// CORRECT: Use dynamorm tags for keys
type User struct {
ID string `dynamorm:"pk" json:"id"` // Partition Key
Email string `dynamorm:"sk" json:"email"` // Sort Key
Name string `json:"name"`
CreatedAt time.Time `json:"created_at"`
}What this does:
- Defines the data structure
- Tells DynamORM which fields are Primary Keys (
pk,sk)
Use this for serverless applications to get sub-15ms cold starts.
package main
import (
"github.com/aws/aws-lambda-go/lambda"
"github.com/pay-theory/dynamorm"
"log"
)
// Global variable for connection reuse
var db *dynamorm.LambdaDB
func init() {
var err error
// Initialize once during cold start
db, err = dynamorm.NewLambdaOptimized()
if err != nil {
log.Fatal(err)
}
}
func handler() (string, error) {
// Use the pre-warmed connection
return "Connected!", nil
}
func main() {
lambda.Start(handler)
}Use this for containers, CLI tools, or local testing.
package main
import (
"github.com/pay-theory/dynamorm"
"github.com/pay-theory/dynamorm/pkg/session"
"log"
)
func main() {
// Standard initialization
db, err := dynamorm.New(session.Config{
Region: "us-east-1",
// Uncomment for local DynamoDB:
// Endpoint: "http://localhost:8000",
})
if err != nil {
log.Fatal(err)
}
}Test your setup by creating an item.
// Create a user
user := &User{
ID: "user_123",
Email: "test@example.com",
Name: "Test User",
CreatedAt: time.Now(),
}
err := db.Model(user).Create()
if err != nil {
log.Printf("Error creating user: %v", err)
} else {
log.Println("User created successfully!")
}- Read Core Patterns for querying and transactions
- See API Reference for the full interface
- Review Struct Definition Guide for advanced modeling
Issue: "ResourceNotFoundException"
- Cause: The table "users" (derived from
Userstruct) does not exist in AWS. - Solution: Create the table in DynamoDB or use
db.CreateTable(&User{})for development.